Results 1 to 10 of 10

Thread: Accessing an event of another form

  1. #1

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Accessing an event of another form

    I have 2 forms...imagine form A and form B...
    I would like to access Form B's paint event from Form A ..

    and I would like to set e.graphics.fillrectangle(example,something) of the other form.

    Can someone advice me about that?
    Thanks
    Godwin

    Help someone else with what someone helped you!

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Accessing an event of another form

    You can check out this link to see if it helps

    http://www.devcity.net/Articles/94/1/multipleforms.aspx

    I think part 3 refers to accessing events or subs on other forms...

    (this link has been getting good use lately)
    Last edited by gigemboy; Feb 15th, 2006 at 03:41 AM.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Accessing an event of another form

    Declare a variable of type FormB as WithEvents in FormA. You can then handle its events just like you would any control or component that you added in the designer. Alternatively you can use the AddHandler statement. A form is an object just like any other, and you can handle its events like you would any other. We're used to handling a form's events inside the form itself but that's not necessary. It is important to remember that each form you design is just a class like any other, and each instance you create is just an object like any other. Form's are not really any different to anything else you work with in .NET.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Accessing an event of another form

    I saw your post before you edited it, which proves that you only just beat me, and yet I must still slink away, defeated...
    Quote Originally Posted by gigemboy
    lol this link has all your answers... (beat you JM...)

    http://www.devcity.net/Articles/94/1/multipleforms.aspx

    3-part article... MUST-HAVE info in regards to working with multiple forms...
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Accessing an event of another form

    lol darn dialup... i cant edit as quick as I need to

  6. #6

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Accessing an event of another form

    Hi Jm,
    Im actually trying to use a function and do this..
    VB Code:
    1. ublic Function changecolor()
    2.         For Each child As Form In parent.MdiChildren
    3.             Dim g As Graphics = child.CreateGraphics()
    4.             Dim rec As New Rectangle(0, 0, child.Width, child.Height)
    5.             Dim lbr As New LinearGradientBrush(rec, Color.DarkOrange, Color.CadetBlue, LinearGradientMode.Vertical)
    6.             g.FillRectangle(lbr, rec)
    7.            
    8.             child.Hide()
    9.  
    10.  
    11.         Next child
    12.     End Function
    but It does what it has to just for a second...I think the logic is wrong...Im not sure how to do that permenant change on the paint event
    Godwin

    Help someone else with what someone helped you!

  7. #7

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Accessing an event of another form

    Thanks for the competition,Im also learning faster and getting to finish my work faster
    Godwin

    Help someone else with what someone helped you!

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Accessing an event of another form

    You can create a Paint event handler in your parent form and then use AddHandler to link it to the Paint event of each child. That handler can then do the drawing. I haven't tested that but I believe the thoery is sound.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Accessing an event of another form

    yep.Ill do that..Ill look up how to do that and go ahead
    Godwin

    Help someone else with what someone helped you!

  10. #10

    Thread Starter
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Accessing an event of another form

    ahh,I seriously cant get this to work...Im struggling for hours..I could only find ways to add addhandler everywhere...
    I want to use a forloop and control all the paintevents in the childform...I dont know how to do it,please help me
    Godwin

    Help someone else with what someone helped you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width