Hack Forums
[C#] How to override function from Form object? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] How to override function from Form object? (/showthread.php?tid=4976624)



How to override function from Form object? - ShadyOverflow - Sep 5, 2015

i have a 15 forms, all i want to do is on the event endresize of the form's object, to do 1 line of code, thats it calling a function to play a sound, now how to override that event/function. i dont want to do, for each form add event code. what if i had 100 forms... :/ tnx in advance.


* - newmecha - Sep 5, 2015

If I understand correctly, you could just create a new control that inherents Form and override OnResizeEnd
PHP Code

<?php 
public partial class SoundForm : Form
    
{
      public 
SoundForm()
      {
      
InitializeComponent();
      }

      protected 
override void OnResizeEnd(EventArgs e)
      {
      
//Play your sound here
      
SystemSounds.Beep.Play();
      
base.OnResizeEnd(e);
      }
    } 

Then to use it you would change your forms to be SoundFrom like
PHP Code

<?php 
public partial class MainForm : SoundForm
    
{
      public 
MainForm ()
      {
      
InitializeComponent();
      }
    } 

This way you wouldnt' have to create an OnResizeEnd event for every new form you create you just make it SoundForm.


* - ShadyOverflow - Sep 5, 2015

(Sep 5, 2015 01:14 PM)newmecha Wrote:  If I understand correctly, you could just create a new control that inherents Form and override OnResizeEnd
PHP Code

<?php 
public partial class SoundForm : Form
    
{
      public 
SoundForm()
      {
      
InitializeComponent();
      }

      protected 
override void OnResizeEnd(EventArgs e)
      {
      
//Play your sound here
      
SystemSounds.Beep.Play();
      
base.OnResizeEnd(e);
      }
    } 

Then to use it you would change your forms to be SoundFrom like
PHP Code

<?php 
public partial class MainForm : SoundForm
    
{
      public 
MainForm ()
      {
      
InitializeComponent();
      }
    } 

This way you wouldnt' have to create an OnResizeEnd event for every new form you create you just make it SoundForm.

exactly what i needed, thank you so much.