Translate

Home > November 2016

November 2016

C# Winform Create Dynamic TabPage and add User Control

Tuesday, November 22, 2016 Category : 0

  List<string> openTabs = new List<string>();
  List<TabPage> openTabPages = new List<TabPage>();

  private void OpenPage(Control control, string OperationName)
        {

            if (!openTabs.Exists(m => m.ToString() == OperationName))
            {
                TabPage tb = new TabPage();
                tb.Text = OperationName;
                tb.Controls.Add(control);
                tabControl1.TabPages.Add(tb);

                // set align position
                int main_width = tabControl1.Width;
                int control_width = control.Width;
                int posX = (main_width - control_width) / 2;
                control.Location = new Point(posX, 0);

                tabControl1.SelectedTab = tb;

                openTabs.Add(OperationName);
                openTabPages.Add(tb);
            }
            else
            {
                foreach (TabPage tb in tabControl1.TabPages)
                {
                    Control ctl = tb.Controls[0];
                    if (ctl != null)
                    {
                        if (ctl.GetType() == control.GetType())
                        {
                            tabControl1.SelectedTab = tb;
                        }
                    }
                }
            }


        }

C# Winform Add Border to UserControl

Category : 0

protected override void OnPaint(PaintEventArgs e)
{

base.OnPaint(e);
int borderWidth = 3;
Color borderColor = SystemColors.AppWorkspace;
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, borderColor,
borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth,
ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid,
borderColor, borderWidth, ButtonBorderStyle.Solid);
}


Source : https://social.msdn.microsoft.com/Forums/windows/en-US/ca9a9df3-c37e-455b-8fae-58d88ed77d90/change-border-around-usercontrol?forum=winformsdesigner
 

Powered by Blogger.