• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 713
  • Last Modified:

call a sub routine from load event on same form in vb.net 2008

I'm trying to call or invoke the following sub routine from a form_load event (or any other sub routine):

 Public Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem

I've tried Public sub, and private sub

I also added:
Imports System.EventArgs
to top of form.

I get this error:

argument not specified for parameter 'e' of 'Public Sub TabControl1_DrawItem(sender As Object, e As System.Windows.Forms.DrawItemEventArgs)'.

Does it need to be in its own class?  Do I need to pass an argument?  If so, how?

any help is appreciated!

-Lbiederman
0
Larry Biederman
Asked:
Larry Biederman
3 Solutions
 
Luis PérezSoftware Architect in .NetCommented:
You need to pass an argument always. But the argument can be Nothing if you don't need the e information inside the code.

You can do this:
Call TabControl1_DrawItem(Nothing, Nothing)
... and it will work, but if you use the "e" variable inside the TabControl1_DrawItem code, then you'll need to explicitly pass the values

Dim e As DrawItemEventArgs = New DrawItemEventArgs
'set e properties
'e.Property = value

Then call the procedure:
Call TabControl1_DrawItem(Nothing, e)

The same said for e can be applied to "sender". If you need sender inside the code, then you'll need to pass a sender.

Hope that helps.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Why would you need to call that method manually?

Did you set OwnerDraw() for your TabControl to OwnerDrawFixed?

If you need to, try:

    TabControl1.Refresh()
0
 
Larry BiedermanSoftware EngineerAuthor Commented:
Thanks  RolandDeschain and Idle_Mind

I found code to change the color of the tab controls (so user can tell which is selected).

The code sub routine begins with the line of code I wrote in my question.

So, my issue was:  now that I've pasted in the sub-routine, how do I call/execute it?

I'll try your code,  RolandDeschain

Thanks Much to you both
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
The DrawItem() event is raised automatically for you when the OwnerDraw() property for your TabControl is set to OwnerDrawFixed.  You don't need to call it manually.
0
 
Larry BiedermanSoftware EngineerAuthor Commented:
Idle_Mind,

Great!  I'll try it.

Lbiederman
0
 
Larry BiedermanSoftware EngineerAuthor Commented:
RolandDeschain,

When I use this code in form_load event:

 Dim e As DrawItemEventArgs = New DrawItemEventArgs
        'set e properties
        e.Property = 1
        Call TabControl1_DrawItem(Nothing, e)

I receive this error message "e is already declaired as a parameter in this method"

I assume e.property =1 is valid for tab 1
if I call my sub routine with (nothing,nothing)  , it doesn't work.

=============================
Idle_mind, your method works fine!  But I still want to learn how to call ByVal

Thank you both,

Lbiederman

Thanks, Lbiederman
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
By the way, the property is actually called DrawMode(), but you probably already figured that out:
http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.drawmode.aspx

Anyways, again, you shouldn't be calling this method yourself manually is it involves painting.  As such, the event is passed a valid Graphics instance via the "e" parameter that you're supposed to use to render that TabControl tabs with:
    Private Sub TabControl1_DrawItem(sender As System.Object, e As System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
        Dim SF As New StringFormat
        SF.Alignment = StringAlignment.Center
        SF.LineAlignment = StringAlignment.Center
        e.Graphics.DrawString("Tab" & e.Index, TabControl1.Font, Brushes.Red, e.Bounds, SF)
    End Sub

Open in new window


I'm using "e.Graphics" in line #5 above.  The .Net framework creates that Graphics instance for you, when appropriate, so that the TabControl is rendered properly.  If you go creating your own parameters for that method, including your own Graphics instance, then anything rendered as a result will simply be erased (overdrawn really) when DrawItem() gets called automatically by system.

If you need the TabControl to redraw itself, then use the Refresh() method as mentioned before.  This will cause all the parameters to be created for you and the event will be raised:

    TabControl1.Refresh()
0
 
Larry BiedermanSoftware EngineerAuthor Commented:
Idle_mind,

thanks much! I do have this working.

Still interested in how to use the e.property with a call "ByVal".
 Maybe RolandDeschain will complete his info.

New Question:  I'm posting a new question about how to change "retrieve property settings" in vb.net if interested.  You've been so helpful in past.

Thanks, Larry
0
 
Larry BiedermanSoftware EngineerAuthor Commented:
Idle_mind,

My new question is titled:
vb.net "retrieve property setting"  Path to database

If interested, I'd like you to answer, as you know this language in detail.

Thanks, Lbiederman
0
 
Larry BiedermanSoftware EngineerAuthor Commented:
Hi aikimark,

Thanks for comment. , but...
I am clueless as to your message.

"replaced VB classic zone with VB.Net zone"
Are you referring to to this question, the new question.. or ???
top of this page says visual basic.net

thanks
0
 
Larry BiedermanSoftware EngineerAuthor Commented:
Dear Administration,
Do not understand.

Maybe you changed the zone already?
The gray box below both my questions DOES say Microsoft visual basic.net.

See attached.

Thanks, Lbiederman
zone.jpg
0
 
aikimarkCommented:
Yes.  My verbiage was past tense.  I had already made the zone change and was letting people know that the zone had been changed.  It was not a request, since you do no have the ability to do such rezoning without using the Request Attention link, asking for assistance.
0
 
Larry BiedermanSoftware EngineerAuthor Commented:
aikimark,
Thank you sir, for your info and help.
Larry
0
 
Larry BiedermanSoftware EngineerAuthor Commented:
Thank you both.  Its working perfectly.
-Lbiederman
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now