I am creating a windows forms button dynamically wrapped in another control. The issue that I am having is that when I set the buttons Enabled property it is still being displayed as though it were enabled (not greyed out) however it is not clickalbe. This leads me to believe that I am not creating the button correctly, or something else like that.
This is the code that I use to create the button.
private System.Windows.Forms.Button CreateWindowsButton(SessionButtonTypes sessionButtonType)
{
windowsButton = new System.Windows.Forms.Button()
{
Top = 3,
Name = sessionButtonType.ToString(),
Width = DeterminButtonWidth(guiElement),
Height = 45,
FlatStyle = FlatStyle.Flat,
BackgroundImage = GUI.Instance.GUIImageElement(guiElement)
};
// set windows button flat border parameters
windowsButton.FlatAppearance.BorderSize = 0;
// for testing
windowsButton.Enabled = false;
}
[UPDATE]
The solution turns out to be putting image element into the image parameter, not the background image parameter.
Remove `FlatStyle = FlatStyle.Flat`.
Using FlatStyle forces the control to have a predefined style which would make the button appear not greyed out even when Enabled is equal to false.
I had the same problem and for me the solution was changing flatstyle from "Standard" to "System"
Related
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.
how do I edit the properties of the button created after setting the property:
columnUltraGrid.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.EditButton;
I would like to add an image and remove the edges of it or just remove the edges and add a word, but then it would have to resize it. If it is not possible to edit, any idea of how it could be done?
By default, the button will be shown using the OS theme. To be able to set the appearance of the cell button you need first to turn off the OS themes:
this.ultraGrid1.UseOsThemes = DefaultableBoolean.False;
Then you can set the ButtonStyle and CellButtonAppearance of the Override:
e.Layout.Override.CellButtonAppearance.Image = MyImage;
e.Layout.Override.ButtonStyle = UIElementButtonStyle.Borderless;
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
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;
How do I set a disabled TextBox's current text color to be the same as its current background color in C#?
Simply doing txtLala.ForeColor = txtLala.BackColor does not seems to work.
This works:
txtLala.Text = "Red";
txtLala.BackColor = System.Drawing.Color.Red;
txtLala.ForeColor = txtLala.BackColor;
txtLala.ReadOnly = true;
Try setting the color, before the readonly. And also check how you are setting the color!
EDIT
Try this
txtLala.Attributes.Add("style","background-color:Red;color:Red");
If you are trying to make it invisible, you know you can set it as
txtLala.Visible = False;
EDIT II
I finally tried
txtLala.Enabled = false;
... you see that grey shadow color! I don't think you can mess with that, it looks to be a browser property setting.
Why not set as ReadOnly or Visible = False?
Maybe you have a good reason for Enabled = false
But you should note:
Use the Enabled property to specify or determine whether a control is functional. When set to false, the control appears dimmed, preventing any input from being entered in the control.
Note The ability to enable or disable functionality is always available. However, dimming and locking the control only works in Microsoft Internet Explorer version 4 and later.
This property propagates down the control hierarchy. Therefore, disabling a container control will disable all child controls within that container.
Note Not all controls support this property. See the indivual controls for details.
It seems to only work for TextBox that is read only. If it is disabled (.Enabled = false). It does not seems to work.
If this is a readonly textbox, you need to explicitly set your BackColor first, then your statement will work.
txtLala.BackColor = System.Drawing.SystemColors.Info;
txtLala.ForeColor = txtLala.BackColor;
Ref: http://bytes.com/groups/net-c/233961-read-only-textbox
Then again, if it's readonly, a label might be better. If you're trying to hide it, perhaps setting .Visible = false would be better still.
Edit: This seems to be a common question on the web. With respect to winforms: This site suggests dropping the box into a frame and setting Enabled = false on the frame, not the textbox. Once you do that, you may be able to maintain control of the forecolor.