Winform menustrip and hiding tabs - c#

Hello I'm thinking of creating a tabcontrol which the tabpages will be filtered by the clicks in the menustrip.
For ex.
My menustrip is in form 1
and my tabcontrol is in form 2
My tabcontrol consist of 7 tabs and I want only 1 tab will be shown at a time.
for example If I click the name in the menustrip it will open/show a new form and the tabcontrol will only show the names tab.
I wonder if its possible because making diff forms for each list seems to be very long.
thanks for reading this.

Problem is, the TabPage control has no Visible property (well, it has, but it does nothing). So you can't hide and show tabs at will. You'll have to remove the tabs that should not be visible.
You could make a form (named TabbedForm) with code like this:
private readonly int _index;
public TabbedForm(int index)
{
this._index = index;
InitializeComponent();
}
private void form_Load(object sender, EventArgs e)
{
for (int index = this.tabControl1.TabPages.Count - 1; index >= 0; index--)
{
if (index != this._index)
this.tabControl1.TabPages.Remove(this.tabControl1.TabPages[index]);
}
}
With each menu button (Clicked event) in your main form you can open a TabbedForm with a different index.

Yes, this will work pretty fine. But I think, you must use the default tab view control for this and that must not create the problem either in you case too.

Related

Keyword Box Form C#

I want to make keyword box like this, and is Richtextbox able to do it?
I only need to enter a keyword that ends with a comma, then it will automatically become a keyword box like that
I could ask ChatGPT, but it's too popular right now too much traffic and I can't enter it now
Thank You
Your difficulty here is how this label should be implemented. It is recommended that you use custom tags.
Let's split the control first. The whole control can be regarded as a selected label interface.
There are many small tabs in the selected tab interface, which are composed of one by one.
One: We focus on implementing the label control in the selected label interface
The label control can inherit UserControl and then add a label control to the UserControl interface to simulate the close button.
public partial class TagControl : BaseRadiusUserControl
Then write a defined close event
[Description("Close Event "), Category("Customize ")]
public event EventHandler CloseClick;
Click X on the label control to trigger the close event
private void close_Click(object sender, EventArgs e)
{
CloseClick?.Invoke(this,e);
}
Then write an assignment method to adjust the size of the control when the text value is greater than 2.
public void SetText(string text)
{
this.Content = text;
if (text.Length > 1)
{
this.Width = 60 + (text.Length - 1) * 20;
}
}
In this way, the small label control is realized!
Two: The selected tab interface uses the flowlaoutpanel control

Visual Studio Custom ToolBox Item Collection Value

i am currently working on my own TabControl, just to give me more options in customization.
To come along with this, i've made my own TabPage too.
Edit: Rewrote my question with pictures:
I want this Field:
After Clicking on "Collection" you gain a new Box to "Add" and "Remove" the Values
So here's what i've done:
If i now hit "Add" some pages appear, if i hit "remove" some pages disappear.
So far so good.
Clicking on "OK" does not show them up (but they are still there, after reopening the menu)
Now the random stuff happens:
If i press "Cancel" all the 'tabs' are generated.
If i open the menu again, all the "tabPages" are shown as there ClassType.
Here is the code of my TabControl Class
//The List for my TabPages
List<FancyTabPage> listPages = new List<FancyTabPage>();
//My Wrapper to get the Menu for the Designer shown in the Picture
public List<FancyTabPage> Pages
{
set { this.listPages = value; drawTabPages(); }
get { return this.listPages; }
}
//My function to generate the buttons
private void drawTabPages()
{
this.Controls.Clear();
resizeTabPages();
int zaehlerMax = listPages.Count;
for (int zaehler = 0; zaehler != zaehlerMax; zaehler++)
{
this.Controls.Add(listPages[zaehler].PageButton);
}
}

Devexpress TabHeader Disappears

I have created ribbon form (XtraMain)and I set IsMdiContainer Property to true,i also add documentManager controle i set MdiParent to XtraMain I have add this code to open child forms
public void ViewChildForm(XtraForm _form)
{
if (!IsFormActived(_form))
{
_form.MdiParent = this;
_form.Show();
}
}
private bool IsFormActived(XtraForm form)
{
bool IsOpenend = false;
if (MdiChildren.Count() > 0)
{
foreach (var item in MdiChildren)
{
if (form.Name == item.Name)
{
tabbedView1.ActivateDocument(item);
IsOpenend = true;
}
}
}
return IsOpenend;
}
and i use this code in click of button to open the child form
private void bbtnEmployee_ItemClick(object sender, ItemClickEventArgs e)
{
FrmEmployee frme = new FrmEmployee();
frme.Name = "FrmEmployee";
ViewChildForm(frme);
}
my problem start when the form contain a LayoutControl for example i have this code that open on click of button
private void btnBonLivraison_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
LayoutControl lc = new LayoutControl();
lc.Dock = DockStyle.Top;
LookUpEdit OrderNumber = new LookUpEdit();
OrderNumber.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
OrderNumber.Properties.DataSource = shippProdu.GetOrderNumber();
OrderNumber.Properties.DisplayMember = "N° Bon de livraison";
OrderNumber.Properties.ValueMember = "N° Bon de livraison";
lc.AddItem(Resources.selectOrderNumber, OrderNumber).TextVisible = true;
lc.Height = 70;
this.Controls.Add(lc);
this.Dock = DockStyle.Top;
lc.BestFit();
the second I click on a button the tabHeader disappears,what cause this problem?and how can I solve it.before I use documentManager I used XtraTabControl and if i click a button to open LayoutControl and after that try to open another form the focus remaining in the first form even when the form two is already opened and if I want to go to form two I must first click on a tab of the first form and then click on tab of the second form , thanks in advance .
this is my main form
and this is when the eader disappears
If DocumentManager resides within the same form to which you add LayoutControl, it is the expected behavior. DocumentManager places a special documents' host onto the main form and set its Dock property to Fill. That is why it is incorrect to place LayoutControl onto the same form and dock it to form edges.
If you need to show tabbed documents and LayoutControl on the same form simultaneously, do not use the MDI mode. Consider the use of a separate UserControl. Place your DocumentManager there. Then, put this UserControl onto your form. Note that in this case UserControl's Dock property should be set to Top or Bottom since LayoutControl should fill all available area or vice versa.

How can I save a dynamically created user control if it contains some buttons in c#?

I am new to C#. I am using windows forms and I have Form1 which contains 2 buttons ( one to create user control at run time and the other creates buttons on user control at run time).
This code creates user control and FlowLayoutPanel (to organize button position) if you click add_UserControl button. And then it creates buttons on FlowLayoutPanel if you click Add_Buttons button and it is all done at run time.
Now in Form1 let's say I created user control and FlowLayoutPanel and then created 5 buttons , how can I save the properties/details of this user control with its FlowLayoutPanel and 5 buttons in SQL database so I can use them later when I run the program? I have been thinking about an idea and I reached the internet but no luck.
Any idea? Please help me. Thank you
public partial class Form1 : Form
{
FlowLayoutPanel FLP = new FlowLayoutPanel();
UserControl uc = new UserControl();
private void add_UserControl_Click(object sender, EventArgs e)
{
uc.Height = 700;
uc.Width = 900;
uc.BackColor = Color.Black;
Controls.Add(uc); //add UserControl on Form1
FLP.Height = 600;
FLP.Width = 800;
FLP.BackColor = Color.DimGray;
uc.Controls.Add(FLP); // add FlowLayoutPanel to UserControl
}
private void Add_Buttons_Click(object sender, EventArgs e)
{
//####### add buttons to FlowLayoutPanel ############
Button dynamicButton = new Button();
dynamicButton.Height = 50;
dynamicButton.Width = 200;
dynamicButton.BackColor = Color.Green;
dynamicButton.ForeColor = Color.Blue;
dynamicButton.Text = "";
FLP.Controls.Add(dynamicButton);
}
}
OK, First you need to create a class that will represent one of the buttons with the properties you need.
class MyButton
{
public string ButtonText {get;set;}
}
Everytime you click and create a button, you actually create an object of this class and add it to a collection or list. Then you would have some other code watching over the collection, and every time it gets a new entry, it creates a new button and sets its Button text to the text property. when a member of list is gone, it removes the button.
If you need more properties to be remembered (color, size, font, ...) you add them to the class as well. If you need for other controls, as well, .... you can always create common parent controls.
Simple.
If you want to be able to reload it, you could define the MyButton class as serializable and store it in xml file, and upon build, reload it.
You should watch into WPF and it's MVVM pattern. It's pretty much similar to it. Also have a look into command pattern, usefull pattern when it commes to this.
You can remember the FlowLayoutsPanels in one SQL table and in another table you could save the buttons which belong to these FlowLayoutPanels.
On Form Load or Application Load, you could check if there are already FlowLayoutPanels and correspending Buttons do exist in the SQL db and if yes then create them, else do nothing.

How to Add Usercontrols on a specific position in a TableLayoutpanel

Team.
I have a Problem with my Tablelayoutpanel. The Tablelayoutpanel is located in the Main-Form and filled with 5 Usercontrols (5 equal Controls, filled with other texts).
Every Usercontrol contains a button. If I click on that button in the UC, 10 other Usercontrols should be added AFTER the clicked Usercontrol.
My Code so far (In the Button-Click Method):
private void bt_Öffnen_Click(object sender, EventArgs e)
{
var ziele = getZielStatement();
foreach (var z in ziele.Where(z => z.Hauptziele.PerspektivenID == gl_PerspektiveID)) // Für jedes Ziel in der jeweiligen Perspektive
{
Uc_Ziele uc_ziel = new Uc_Ziele();
uc_ziel.gl_Unterziel = z;
this.Parent.Controls.Add(uc_ziel);
}
}
The problem is, that the Controls are added at the end of TableLayoutpanel. They should be added after the clicked Usercontrol.
I cant do it without help. Hope you get what i want.
Greets, Daniel
After you've added the control use the SetChildIndex method to move it to its correct position.
Check out this post for further info
How to add rows into middle of a TableLayoutPanel

Categories

Resources