Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabbed user interface in C#

I want to create a simple tabbed interface app. I did it before in WPF using an usercontrol inside of each tab, and I comunicate with the principal form searching for a parent element (the form, or the tab control)

How could I made the same in WinForms? Which element need I put inside of each tab?

Thanks.

like image 637
Jonathan Avatar asked Apr 23 '26 22:04

Jonathan


2 Answers

You can use pretty much the same approach in a winforms application. You can add user controls to the tab pages of a TabControl on a form. Inside the user control code you can use the FindForm method to get hold of the parent form.

However, I would suggest that you instead use events to communicate "out" from the controls, in order to make them less dependent on their surroundings.

like image 116
Fredrik Mörk Avatar answered Apr 25 '26 12:04

Fredrik Mörk


TabPage and TabControl might be classes and components you would want to look into. Using the Parent property you can access the owning form and thus communicate with it or between tabs, should you need it.

Though, as Fredrik Mörk suggests, using events is a far better practice. =)

like image 42
J. Steen Avatar answered Apr 25 '26 12:04

J. Steen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!