开发者

vb.net 2008/2010 tabcontrol and code

开发者 https://www.devze.com 2023-02-09 03:06 出处:网络
I am looking for a way to be able to use the tab control on my main form and transfer all 3 other forms onto that main form that has the tab control.开发者_Python百科 Problem being is that some functi

I am looking for a way to be able to use the tab control on my main form and transfer all 3 other forms onto that main form that has the tab control.开发者_Python百科 Problem being is that some functions are named the same in each of the septate forms i want to bring into just one for the tab control.

Is there a way to separate the code for each form ON the main form of the tab control so i don't have to rename/recode each of the 3 forms i want to place on the main form of the tab control?

As an example: Form1 has a function called upDateMe() form2 has a function called upDateMe()

So now the main form would look like this:

Friend Class frmPW
  Function sub upDateMe()
     blah blah
  End Function

  Function sub upDateMe()
     blah blah
  End Function

so when i put both form1 and form2 code on the main form where the tab control is, its going to tell me that i have a duplicate function name.

Thanks for any help!

David


Why not add the what as a parameter to the update-sub? I don't know what the functions are doing, but assuming that they load some data and bind Controls to it, you could provide a parameter that you can use to separate the logic/datasource.

Another possibility would be to simply rename the subs so that you can distinguish their purpose.

Last but not least you could encapsulate the whole business logic and databinding in one class/UserControl and instantiate it for every ex-form.


Consider User Controls.

There are plenty of examples available. You might want to start with this walkthrough on MSDN: Walkthrough: Authoring a Composite Control with Visual Basic

One thing to watch for: The project type you'll create is actually 'Windows Forms Control Library', not 'Windows Control Library' like the 'Creating the Project' section, step 2 says.

You would create a User Control for each form in your project. Each of these UCs can be added to a tab on your main form and can be treated like any other standard Windows control.

For example - you can create a UC for your form1 called ctlForm1 and add it to Visual Studio's Toolbar. You can use the WinForm designer to drop an instance of your control in a tab page on your new main form and call it, say, ucForm1. To call the UC's upDateMe method you would simply call:

ucForm1.upDateMe()

You can thne create a UC for your form2, add it to your Toolbar and drop an instance of it on a different tab page on your main form (calling that instance ucForm2). You can call that control's upDateMe method like this:

ucForm2.upDateMe()

You'll want to learn about User Controls; they're a great way to encapsulate logic, events and UI elements into descrete, reusable components.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号