I have a Devexpress MVC Menu in razor and I want to set the margins on the menu items so the menu will fit horizontally on the page. There is a setting.ControlStyle for padding but not margins.
Is there any way I can change the margins so it will fit across the page?
#Html.DevExpress().Menu(
settings =>
{
settings.Name = "mDataBinding";
settings.AllowSelectItem = true;
settings.Width = 1080;
settings.ControlStyle.Paddings.PaddingLeft = 0;
settings.ControlStyle.Paddings.PaddingRight = 0;
settings.ControlStyle.Font.Size = 9;
settings.ControlStyle.ItemSpacing = 1;
}).BindToSiteMap("~/Styles/SiteMaps/Main.sitemap", false).GetHtml()
Here is what it currently looks like
I recommend settings.Width = Unit.Percentage(100);
Related
I've been using a UserControl to display a list of controls. I initially had AutoScroll enabled, and then opted to not using it. I chose against using it as it stood out and simply didn't 'look' good with the controls theme I've been using.
I took a shot at a framework called MetroFramework, and I've opted to use the MetroScrollBar scrollbar control for a vertical scrollbar.
I've fully disabled AutoScroll, and I then decided to implement the Scrollbar. I simply did this by:
scbMain.Scroll += (sender, e) => { VerticalScroll.Value = scbMain.Value; };
(where scbMain is the Scrollbar I'm discussing)
This works, but not as expected. As soon as I scroll, I get a crazy flickering effect from the default scrollbar, as shown here. A longer list has the same effect, but more pronounced.
I've attempted to hide the existing scrollbars:
VerticalScroll.Visible = false;
HorizontalScroll.Visible = false;
VerticalScroll.Enabled = false;
HorizontalScroll.Enabled = false;
This has had no effect on fixing my issue.
It should be noted: My scrollbar is docked to the right and there're no other container controls within the UserControl.
Ok. Problem solved. The issue was in this line of code:
scbMain.Scroll += (sender, e) => { ----> /*(Here*/ VerticalScroll.Value = scbMain.Value; <---- };
You are actully setting the scroll value of your user control, basically you tell the system to invoke the autoscroll property to set the value!
The correct way is to NOT autoscroll the user control but to scroll a container inside eg a panel. So add a panel to your user control. You are going to scroll the panel and all the controls inside it (in this example i will add the button).
this.btnExample.Location = new System.Drawing.Point(62, 0);
this.btnExample.Name = "btnExample";
this.btnExample.Size = new System.Drawing.Size(75, 390);
this.btnExample.TabIndex = 1;
this.btnExample.Text = "Out of Bounds";
this.btnExample.UseVisualStyleBackColor = true;
this.panel1.Controls.Add(this.btnExample);
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(270, 391); //the width must fit inside your user control and the height was arbitrary
this.panel1.TabIndex = 2;
this.Controls.Add(this.panel1);
this.Controls.Add(this.scbMain);
this.Name = "CtrlScroll";
this.Size = new System.Drawing.Size(474, 300);
The scrolling:
public CtrlScroll() {
InitializeComponent();
scbMain.Scroll += ( sender, e ) => {
//Normally the if statement whouldn't be needed but the metro srollbar
//has a weird behaviour when the scroll value becomes max
if( scbMain.Value > panel1.Height - this.Height ) {
panel1.Top = -( panel1.Height - this.Height );
}
else {
panel1.Top = -scbMain.Value;
};
};
int maxVertical = panel1.Height;
// SmallChange is typically 1%.
int smallChangeVertical = Math.Max( (int)( maxVertical / 100 ), 1 );
// LargeChange is one page.
int largeChangeVertical = this.Height;
scbMain.Minimum = 0;
scbMain.Maximum = maxVertical;
scbMain.SmallChange = smallChangeVertical;
scbMain.LargeChange = largeChangeVertical;
}
I have the problem that the text inside my panel gets cut of strangely. The panel is located inside a textbox. But even if I replace the textbox by a flowlayoutpanel, I have the same issue.
Code:
List<string> list = datenbank.FerienAuswahl(monat, jahr);
int i = 0;
//Create Panel
try
{
//Fill Panel
do
{
Label panel = new Label();
panel.Name = "panel" + i;
panel.Height = 30;
panel.Width = 400;
panel.AutoSize = false;
panel.TextAlign = ContentAlignment.MiddleCenter;
panel.ForeColor = Color.Black;
panel.Text = list[i];
Label ferien = new Label();
panel.Controls.Add(ferien);
tbFerien.Controls.Add(panel);
i++;
} while (i < list.Count);
}
catch { }
Result:
I have already tried to change the width of the panel. But as result I only get a messed up alignment of the text.
The only settings of the textbox I have changed are these:
Multiline: True
TextAlign: Center
Size: 359; 125
Does Someone know what else I could try ?
These lines worry me:
Label panel = new Label();
Label ferien = new Label();
panel.Controls.Add(ferien);
tbFerien.Controls.Add(panel);
It seems to me you are adding one label to another. That's not good. Use a Panel or TableLayoutPanel instead of the actual panel and make sure you have your positioning good.
I am writing my Windows Forms app. And I have some problem with TableLayoutContainer element. Or rows are superpose (without needed scroll bar) or there is a big interval between first and second row.
I need a container with dynamic changing sizes according to Form size, with auto vertical scroll (if the container's size to big). Please help me to correct my code or container's properties.
Label LabelG = new Label[len];
NumericUpDown NumberControlBars = new NumericUpDown[len];
for (int i = 0; i < len; i++)
{
TablePanelContainer.RowCount++;
TablePanelContainer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
LabelG[i] = new System.Windows.Forms.Label();
LabelG[i].Name = "Label" + i.ToString();
LabelG[i].Size = new System.Drawing.Size(40, 23);
LabelG[i].Text = Groups[i].ToString();
LabelG[i].Dock = DockStyle.Right;
LabelG[i].Anchor = (AnchorStyles.Right | AnchorStyles.Top);
LabelG[i].TextAlign = ContentAlignment.MiddleRight;
TablePanelContainer.Controls.Add(LabelG[i], 0, i);
NumberControlBars[i] = new System.Windows.Forms.NumericUpDown();
NumberControlBars[i].Name = "Label" + i.ToString();
NumberControlBars[i].MaximumSize = new System.Drawing.Size(40,23);
NumberControlBars[i].Text = "0";
NumberControlBars[i].Dock = DockStyle.Left;
NumberControlBars[i].Anchor = (AnchorStyles.Left | AnchorStyles.Top);
TablePanelContainer.Controls.Add(NumberControlBars[i], 1, i);
}
Properties
Bug
I have recreated your functionality in a small app. These are the settings for your TablePanelLayout control
Anchor: Top, Bottom, Left, Right
AutoScroll: True
AutoSize: False
Specially the AutoSize setting to false is important. If you don't do that the control will resize itself to the height needed to accommodate all rows. Because the container has enough space in that case to show everything it will not show the scrollbars. It doesn't care that its size doesn't fit on the form.
This is what the designer should look like:
To overcome the quirks with the first row I adapted the Style of that first row. It looks like the designer plays some tricks here. Your code will look like this.
tableLayoutPanel1.SuspendLayout();
// adapt styling of first row
if (tableLayoutPanel1.RowStyles.Count > 0)
{
tableLayoutPanel1.RowStyles[0].SizeType = SizeType.Absolute;
tableLayoutPanel1.RowStyles[0].Height = 25F;
}
for(int i=0; i<100; i++)
{
var lbl = new Label();
lbl.Text = i.ToString();
tableLayoutPanel1.Controls.Add(lbl, 0, i);
var num = new NumericUpDown();
tableLayoutPanel1.Controls.Add(num,1 ,i);
tableLayoutPanel1.RowCount++;
}
tableLayoutPanel1.ResumeLayout();
When run this is the result:
I got a problem in regards to autoscrolling of a system.windows.forms.panel. I have a panel that i fill with checkboxes, and if the height requirement of the total amount of checkboxes exceeds the height of the panel it should add a vertical scrollbar. My problem is that it is handles the vertical scrollbar as intended, but it also display a horizontal scrollbar wich is not needed. I adjust the width of the panel by adding System.Windows.Forms.SystemInformation.VerticalScrollBarWidth to the panel width.
int prevMainTop = 0;
int maxWidth = 0;
foreach (List<String> arr in folderArr)
{
if (arr[0].Length * 7 > maxWidth) { maxWidth = arr[0].Length * 7; }
}
foreach (List<String> arr in folderArr)
{
CheckBox cb = new CheckBox();
cb.BackColor = Color.Chocolate;
cb.Checked = true;
cb.AutoSize = false;
cb.Width = maxWidth;
cb.Name = arr[0];
cb.Text = arr[0];
cb.Tag = arr[1];
cb.Top = prevMainTop;
prevMainTop = prevMainTop + 25;
this.mainPanel.Controls.Add(cb);
}
this.mainPanel.Width = maxWidth + System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;
Image showing the unwanted added space to the right of the checkboxes, color added to control background to illustrate the size of the control.
Check the AutoScrollMargin and AutoScrollMinSize properites of the panel. AutoScrollMargin should be (0,0) and you may need to also set AutoScrollMinSize to the maxWidth value.
My form contains a tab control. On one tab, I have three groupboxes. Each groupbox must have the height of one third of the height of the tab.
Right now I have this code on the layout event of the tab control:
// Determine the position of the group panels (gp)
this.SuspendLayout();
int oneThird = (tabPanel.Height - 5) / 3;
if (_currentQuestion != null && _currentQuestion.QuestionTypes == QuestionTypes.Infofield)
{
gpExplanation.Visible = false;
gpFillInHelp.Visible = false;
gpFillInQuestion.Height = oneThird * 3;
}
else
{
gpExplanation.Visible = true;
gpFillInHelp.Visible = true;
gpFillInQuestion.Height = oneThird;
gpExplanation.Height = oneThird;
gpFillInHelp.Height = oneThird;
}
// Determine position of the appointment and achievement group panels
int height = tabPanel.Height - 30;
int half = height / 2;
pnlAppointment.Height = half;
this.ResumeLayout();
I also have this code in the constructor of my form:
// Set styles which prevent screen flickering
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
this.DoubleBuffered = true;
What is in your eyes the best way to set the height of the groupboxes? When the form resizes, the groupboxes height must be one third of the panels height.
I also want as less as possible flickering on the screen.
You can use a TableLayoutPanel for this. In the panel you can specify the RowStyle
such that it sized as a percentage of the parent control:
tableLayoutPanelGroupBoxes.ColumnCount = 1;
tableLayoutPanelGroupBoxes.RowCount = 3;
tableLayoutPanelGroupBoxes.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33333F));
tableLayoutPanelGroupBoxes.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33334F));
tableLayoutPanelGroupBoxes.RowStyles.Add(new RowStyle(SizeType.Percent, 33.33334F));
Just set the DockStyle on your group boxes to DockStyle.Fill and add them to the table layout panel. You can use the designer to do this.
Use Achor property of the group boxes.