how to add vertical scroll bars in tabcontrol/tabpages - c#

I am designing an application in which i am using tab-control, and in one of the tab-page the information i want to display in bigger than the form size, the information is displayed in various text-boxes. i tried by adding following lines in designer code but it is still not working.
this.AutoScroll = true;
this.AutoScrollMargin = new System.Drawing.Size(20, 20);
this.AutoScrollMinSize = new System.Drawing.Size(this.Width, this.Height);
any help would be appreciated.

You have to set the AutoScroll on the TabPage, not the Form, you can do this at design time by selecting your tabpage first, then set the AutoScroll to true in the Properties window, or you can do by code like this:
tabPage1.AutoScroll = true;
//do the same for other tabPages

Notice that "this" refer to whole class (your form).
Increase the value like this:
tab.AutoScrollMinSize = new System.Drawing.Size(1000,1000);
Or you can add panel1 to your tab, then dock it into the tab:
panel1.dock = dockingSyle.Fill;
Now you can make panel1 scrollable.

Related

UserControl inside Panel inside UserControl not working

I am having some trouble creating the template of my application :
I am making some dynamic parts of forms and I use a panel in which I include my User Control according to the choice of the user. The panel has the same size as the user control but it doesn't work at runtime. The panel in which the UC is included is inside another UC also.
I tried autoSize = true, fixed size and many things but I don't know why it goes like this. Any idea?
Some parts of my code to load the User Control :
UC_panel.Controls.Clear();
UC_ADDRESS uca = new UC_ADDRESS();
uca.Dock = DockStyle.Fill;
uca.AutoSize = true;
UC_panel.Controls.Add(uca);
My UserControl for the address
At runtime it goes bigger
Since you set
uca.Dock = DockStyle.Fill;
and also
uca.AutoSize = true;
(which is redundant)
it is possible that some other container has its AutoScaleMode set to Font and its font size is bigger.

Autoscroll not working on SplitContainer in WindowsForms C#

I have a Windows Forms, which contains a SplitContainer control. The SplitContainer has a DataGridView in SplitContainer.Panel1 and a UserControl in SplitContainer.Panel2. In SplitContainer.Panel1 the DataGridView has autoscrolling working fine (I did not do anything here, it's automatic I guess), but on SplitContainer.Panel2 it doesn't.
The UserControl loaded in SplitContainer.Panel2 has two Panels inside, just in case someone would ask :) Autoscroll seems to work when a very little portion of the SplitContainer.Panel2 is visible, but not on the whole UserControl.
This is the relevant code in constructor of Form:
InitializeComponent();
var infoPanel = InfoPanelUserControl.Instance;
infoPanel.Dock = DockStyle.Fill;
infoPanel.AutoScroll = true;
dataSplitContainer.Panel2.Controls.Add(infoPanel);
dataSplitContainer.Panel2Collapsed = true;
This is the method executed when clicking a cell in DataGridView:
dataSplitContainer.Panel2Collapsed = false;
var row = Convert.ToInt32(((DataGridView) sender).Rows[e.RowIndex].Cells["Id"].Value);
var record = Repository.Instance.Passmann.Vaults.First().Records.Single(x => x.Id == row);
InfoPanelUserControl.Instance.LoadInfo(record);
I've tried adding AutoScroll property on different controls (to SplitContainer.Panel2, UserControl) and also AutoSize, but none of these seems to work.
Thanks for any advice.

windows forms can't add more components

I want to build a form that has 100 label and 100 text box
what I did is:
add new form
add panel to that form using drag and drop
change the dock property of that panel to fill
change the AutoScroll property to True
start adding the labels and text boxes using drag and drop
The problem
I added like 40 labels and text boxes but I can't add any more because I can't expand the form nor the label vertically.
Note
I can minimize the size of the panel and a vertical scroll bar appears. (maybe this information helps you to help me).
A data entry window with that many text boxes is going to require scrolling. So set the Panel's AutoScrollMinSize property to, say, (1000, 1000) as a first guess. You'll see the scrollbars appear. They work at design time as well, allowing you to scroll the panel and place the controls. High odds you should be using a DataGridView btw.
Something that needs to be said: the odds that you can get a human to enter 100 data items without any mistake are very close to zero. A very frustrating job for the hapless user, it will take him 10 or more minutes only to arrive at failure. Create a user friendly UI, one that partitions the data entry job in small steps that can be successfully completed. Automatically solves this problem as well.
Set parent form's properties AutoSize and AutoScroll to true. Then disable docking for your panel. This way you can set any size to panel and scroll form contents to add new controls. When panel design is done, set docking to Fill again.
Or you can set position for newly added controls using Properties panel. This will move controls to appropriate position on the panel.
This is a sample method I've used to add an unknown number of controls to a form. The trick is a FlowLayoutPanel.
As has been said before: you don't want 100 manually added controls on your page.
private void AddMappingControls() {
HeaderFlowLayoutPanel.Controls.Clear();
MappingFlowLayoutPanel.Controls.Clear();
Label sourceHeaderLabel = new Label();
sourceHeaderLabel.Text = "Velden in Excel (bron)";
sourceHeaderLabel.Name = "BronLabel";
sourceHeaderLabel.Width = MappingFlowLayoutPanel.Width / 2 - 20;
HeaderFlowLayoutPanel.Controls.Add(sourceHeaderLabel);
Label destinationHeaderLabel = new Label();
destinationHeaderLabel.Text = "Velden in Word sjabloon (bestemming)";
destinationHeaderLabel.Name = "BestemmingLabel";
destinationHeaderLabel.Width = MappingFlowLayoutPanel.Width / 2 - 20;
HeaderFlowLayoutPanel.Controls.Add(destinationHeaderLabel);
foreach (string destination in this.destinationFields) {
ComboBox sourceFieldComboBox = new ComboBox();
sourceFieldComboBox.BindingContext = new System.Windows.Forms.BindingContext();
sourceFieldComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
//sourceFieldComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
sourceFieldComboBox.Name = destination + "ComboBox";
sourceFieldComboBox.ValueMember = destination;
sourceFieldComboBox.DataSource = this.sourceFields;
sourceFieldComboBox.Width = MappingFlowLayoutPanel.Width / 2 - 20;
MappingFlowLayoutPanel.Controls.Add(sourceFieldComboBox);
Label nameLabel = new Label();
nameLabel.Text = destination;
nameLabel.Name = destination + "Label";
nameLabel.Width = MappingFlowLayoutPanel.Width / 2 - 20;
MappingFlowLayoutPanel.Controls.Add(nameLabel);
}
}
I meant exactly the same as MeanGreen but he was first. I have created sample solution: https://www.amazon.com/clouddrive/share?s=i9N7raPPQPEjOdHPRn99uE

Create a control that has menu's characteristic?

Can I create a control that has 2 menu's characteristic:
Do not take form's focus on clicking.
Automically disappear when clicking outside.
I intend to draw it manually, but I realise I can't draw outside of form's border like system menu.
You are describing the ToolStripControlHost, which can contain any control you want. Paired with the ToolStripDropDown, and you have a very effective custom drop down control that will not take focus from the main form, and will close when clicked outside of it:
Dim toolDrop As New ToolStripDropDown()
Dim toolHost As New ToolStripControlHost(myControl)
toolHost.Margin = New Padding(0)
toolDrop.Padding = New Padding(0)
toolDrop.Items.Add(toolHost)
toolDrop.Show(Me, New Point(0, 0))
Whatever myControl is, sometimes you have to set the MinimumSize of it equal to the size of the control. There are events you can handle for the ToolStripDropDown such as, Opening and Closing.
what kind of control? is it a CommandButton? if so, you can set Allow Focus Property to False.

Disable resizing of a Windows Forms form

How do I turn off the user's ability to resize a Windows Forms form?
I'm having it resize itself on a click.
Take a look at the FormBorderStyle property
form1.FormBorderStyle = FormBorderStyle.FixedSingle;
You may also want to remove the minimize and maximize buttons:
form1.MaximizeBox = false;
form1.MinimizeBox = false;
First, select the form.
Then, go to the properties menu.
And change the property "FormBorderStyle" from sizable to Fixed3D or FixedSingle.
More precisely, add the code below to the private void InitializeComponent() method of the Form class:
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
Explanation
By default, FormBorderStyle property has the sizable value FormBorderStyle.Sizable assigned. Which enables form to be resized.
There are 7 kinds of FormBorderStyle property values available to use.
None
FixedSingle
Fixed3D
FixedDialog
Sizable
FixedToolWindow
SizableToolWindow
Depending upon the kind of form, we can assign the appropriate value accordingly.
Assuming your form name is form1.
Choose any one from below to make it as Fixed
FixedSingle, Fixed3D, FixedDialog makes the form non-resizeable, assigning None will also work but won't make sense without a control box in case.
Code
Code snippets below, use any one of them
FixedSingle
form1.FormBorderStyle = FormBorderStyle.FixedSingle;
Fixed3D
form1.FormBorderStyle = FormBorderStyle.Fixed3D;
FixedDialog
form1.FormBorderStyle = FormBorderStyle.FixedDialog;
None [Optional] Note: There'd no control box
form1.FormBorderStyle = FormBorderStyle.None;
Or, Graphically
We can apply it graphically like this.
Make sure you've selected the form which you want to make it fixed size. then you'll see a property named FormBorderStyle property there in Properties window.
Another way is to change properties "AutoSize" (set to True) and "AutosizeMode" (set to GrowAndShrink).
This has the effect of the form autosizing to the elements on it and never allowing the user to change its size.
None of these answers worked for me, perhaps because my window had a status bar. To fix I did this:
StatusStripObject.SizingGrip = False
The same works for a StatusBar object, e.g.:
StatusBarObject.SizingGrip = False
There is far more efficient answer: just put the following instructions in the Form_Load:
this.MinimumSize = new Size(Width, Height);
this.MaximumSize = this.MinimumSize;

Categories