Click here to Skip to main content
15,917,329 members
Home / Discussions / C#
   

C#

 
GeneralRe: Showing a continuously refreshed form during calculations Pin
Luc Pattyn19-May-10 8:07
sitebuilderLuc Pattyn19-May-10 8:07 
GeneralRe: Showing a continuously refreshed form during calculations Pin
harold aptroot19-May-10 8:15
harold aptroot19-May-10 8:15 
GeneralRe: Showing a continuously refreshed form during calculations Pin
Luc Pattyn19-May-10 8:17
sitebuilderLuc Pattyn19-May-10 8:17 
GeneralRe: Showing a continuously refreshed form during calculations Pin
PIEBALDconsult19-May-10 8:59
mvePIEBALDconsult19-May-10 8:59 
GeneralRe: Showing a continuously refreshed form during calculations Pin
PIEBALDconsult19-May-10 6:23
mvePIEBALDconsult19-May-10 6:23 
GeneralRe: Showing a continuously refreshed form during calculations Pin
Hankyaku19-May-10 7:12
Hankyaku19-May-10 7:12 
GeneralRe: Showing a continuously refreshed form during calculations Pin
Luc Pattyn19-May-10 9:43
sitebuilderLuc Pattyn19-May-10 9:43 
GeneralRe: Showing a continuously refreshed form during calculations Pin
PIEBALDconsult19-May-10 9:30
mvePIEBALDconsult19-May-10 9:30 
Luc Pattyn wrote:
generalize without much expense


Code is cheap.


I defined an abstract class EventArgsWrapper which derives from EventArgs then derived EnabledEventArgs (to hold a bool) and TextEventArgs (to hold a string). My DoSomething method can then use the provided EventArgs to decide what task is requested.

private void
DoSomething
(
    object           sender
,
    System.EventArgs e
)
{
    System.Windows.Forms.Control c = sender as System.Windows.Forms.Control ;

    if ( c == null )
    {
        throw ( new System.InvalidCastException ( "sender must be a System.Windows.Forms.Control" ) ) ;
    }

    if ( c.InvokeRequired )
    {
        c.Invoke ( new System.EventHandler ( DoSomething ) , sender , e ) ;
    }
    else
    {
        EventArgsWrapper w = e as EventArgsWrapper ;

        if ( w == null )
        {
            throw ( new System.InvalidCastException ( "e must be an EventArgsWrapper" ) ) ;
        }

        if ( w is EnabledEventArgs )
        {
            c.Enabled = ((EnabledEventArgs) w).Enabled ;
        }
        else if ( w is TextEventArgs )
        {
            c.Text = ((TextEventArgs) w).Text ;
        }
    }

    return ;
}

            // sender is already known to be a Control in this case
            string temp = sender.Text ;

            this.DoSomething ( sender , new EnabledEventArgs ( false , e ) ) ;
            this.DoSomething ( sender , new TextEventArgs ( "Wait..." , e ) ) ;

            /* Long-running process */
            System.Threading.Thread.Sleep ( 5000 ) ;

            this.DoSomething ( sender , new TextEventArgs ( temp , e ) ) ;
            this.DoSomething ( sender , new EnabledEventArgs ( true , e ) ) ;


I suppose I could use Reflection to enumerate the public properties of the EventArgs and use them to set the sender's properties that match by name (and type?)... nah, far too much work. Maybe a Dictionary...
GeneralRe: Showing a continuously refreshed form during calculations Pin
Luc Pattyn19-May-10 9:52
sitebuilderLuc Pattyn19-May-10 9:52 
GeneralRe: Showing a continuously refreshed form during calculations Pin
PIEBALDconsult19-May-10 10:34
mvePIEBALDconsult19-May-10 10:34 
GeneralRe: Showing a continuously refreshed form during calculations Pin
Luc Pattyn19-May-10 11:15
sitebuilderLuc Pattyn19-May-10 11:15 
AnswerRe: Showing a continuously refreshed form during calculations Pin
#realJSOP19-May-10 9:21
professional#realJSOP19-May-10 9:21 
QuestionWhat do I require to create a program that controls a device driver? Pin
Ian Durward19-May-10 2:47
Ian Durward19-May-10 2:47 
AnswerRe: What do I require to create a program that controls a device driver? Pin
Henry Minute19-May-10 3:31
Henry Minute19-May-10 3:31 
AnswerRe: What do I require to create a program that controls a device driver? Pin
Luc Pattyn19-May-10 3:51
sitebuilderLuc Pattyn19-May-10 3:51 
AnswerRe: What do I require to create a program that controls a device driver? Pin
The Man from U.N.C.L.E.19-May-10 4:06
The Man from U.N.C.L.E.19-May-10 4:06 
QuestionMuslim Holiday in Georgian Calendar Pin
dataminers19-May-10 1:47
dataminers19-May-10 1:47 
AnswerRe: Muslim Holiday in Georgian Calendar Pin
Pete O'Hanlon19-May-10 2:26
mvePete O'Hanlon19-May-10 2:26 
GeneralRe: Muslim Holiday in Georgian Calendar Pin
Luc Pattyn19-May-10 3:29
sitebuilderLuc Pattyn19-May-10 3:29 
GeneralRe: Muslim Holiday in Georgian Calendar Pin
Pete O'Hanlon19-May-10 3:43
mvePete O'Hanlon19-May-10 3:43 
GeneralRe: Muslim Holiday in Georgian Calendar Pin
Luc Pattyn19-May-10 3:53
sitebuilderLuc Pattyn19-May-10 3:53 
GeneralRe: Muslim Holiday in Georgian Calendar Pin
Luc Pattyn19-May-10 9:32
sitebuilderLuc Pattyn19-May-10 9:32 
AnswerRe: Muslim Holiday in Georgian Calendar Pin
The Man from U.N.C.L.E.19-May-10 2:41
The Man from U.N.C.L.E.19-May-10 2:41 
AnswerRe: Muslim Holiday in Georgian Calendar Pin
riced19-May-10 3:41
riced19-May-10 3:41 
QuestionUse event from C++ library in C# application Pin
Programm3r19-May-10 1:39
Programm3r19-May-10 1:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.