C# Windows Forms Combobox not working correctly - c#

I'm currently working on a backup program. On Friday everything worked without any problems and the project was almost finished.
Today I started Visual Studio without doing anything else. And every combo box I add has the drop-down menu shifted to the right.
I have removed all the code and created new combo boxes, but they are still wrong displayed. I never had this problem before.
Maybe it's the Form Designer, I haven't checked it yet. Maybe someone has had this problem before and can help me? I would be very grateful.
public Form1()
{
InitializeComponent();
this.CenterToScreen();
this.MaximizeBox = false;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.Font = new Font("Arial", 10, FontStyle.Regular);
this.PathSettingsPanel.BackColor = System.Drawing.Color.LightGray;
this.UsernameComboboxCreate.DropDownStyle = ComboBoxStyle.DropDownList;
this.SelectBackupSend.DropDownStyle = ComboBoxStyle.DropDownList;
this.DtDUsernameSource.DropDownStyle = ComboBoxStyle.DropDownList;
this.DtDUsernameTarget.DropDownStyle = ComboBoxStyle.DropDownList;
this.indicator.Text = string.Empty;
this.SendBackupIndicator.Text = string.Empty;
this.IndicatorSource.Text = string.Empty;
this.IndicatorTarget.Text = string.Empty;
this.panel3.BorderStyle = BorderStyle.FixedSingle;
this.panel4.BorderStyle = BorderStyle.FixedSingle;
this.panel5.BorderStyle = BorderStyle.FixedSingle;
this.ServerBackups.View = View.Details;
this.Updating.Visible = true;
this.ServerBackups.UseCellFormatEvents = true;
Serverpath.Text = Main.ReadPathFromFile("server");
PopulateListBoxes();
StartCopy.DoWork += backgroundWorker1_DoWork;
StartCopy.RunWorkerCompleted += backgroundWorker1_RunWorkerCompleted;
StartCopy.WorkerReportsProgress = true;
StartCopy.WorkerSupportsCancellation = true;
FillProgressBar.DoWork += backgroundWorker2_DoWork;
FillProgressBar.RunWorkerCompleted +=
backgroundWorker2_RunWorkerCompleted;
FillProgressBar.ProgressChanged +=
backgroundWorker2_ProgressChanged;
FillProgressBar.WorkerReportsProgress = true;
FillProgressBar.WorkerSupportsCancellation = true;
}
Edit
I've tried a little around. The problem persists even if I create a new project and copy code and forms.
When I create a combobox outside the tab control, it works as it should. Once I click a combobox inside the tab control it will be displayed incorrectly. After that the box which works at the beginning doesn't work anymore.
Okay the problems seems to be the tabcontrol. I just have no idea why.

Related

Devexpress Checkbutton Blueline border - how to remove

I am currently working on a devexpress project and I am using the checkbutton tool. I have it doing everything I want except for a very annoying sick looking blueline that shows up on appearance.hover and appearance.pressed.
If anything at all I would expect a color that goes with the theme but a constant blueline no matter what skin is selected is annoying and feels like an old html design.
I have tried setting the bordercolor and all but still.
Below is my code of what I have tried by far from form.Designer.cs;
this.cBtnFilter.AllowFocus = false;
this.cBtnFilter.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cBtnFilter.AppearanceDisabled.Options.UseBackColor = true;
this.cBtnFilter.AppearanceHovered.BorderColor = System.Drawing.Color.White;
this.cBtnFilter.AppearanceHovered.Options.UseBackColor = true;
this.cBtnFilter.AppearanceHovered.Options.UseBorderColor = true;
this.cBtnFilter.AppearancePressed.BorderColor = System.Drawing.Color.White;
this.cBtnFilter.AppearancePressed.Options.UseBackColor = true;
this.cBtnFilter.AppearancePressed.Options.UseBorderColor = true;
this.cBtnFilter.ImageOptions.AllowGlyphSkinning = DevExpress.Utils.DefaultBoolean.False;
this.cBtnFilter.ImageOptions.Location = DevExpress.XtraEditors.ImageLocation.MiddleCenter;
this.cBtnFilter.ImageOptions.SvgImage = global::form.Properties.Resources.icon_filter;
this.cBtnFilter.ImageOptions.SvgImageSize = new System.Drawing.Size(40, 40);
this.cBtnFilter.Location = new System.Drawing.Point(355, 40);
this.cBtnFilter.LookAndFeel.SkinName = "The Bezier";
this.cBtnFilter.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.UltraFlat;
this.cBtnFilter.LookAndFeel.UseDefaultLookAndFeel = false;
this.cBtnFilter.Name = "cBtnFilter";
this.cBtnFilter.PaintStyle = DevExpress.XtraEditors.Controls.PaintStyles.Light;
this.cBtnFilter.ShowFocusRectangle = DevExpress.Utils.DefaultBoolean.False;
this.cBtnFilter.Size = new System.Drawing.Size(50, 50);
toolTipTitleItem4.Text = "Show active Only";
superToolTip4.Items.Add(toolTipTitleItem4);
this.cBtnFilter.SuperTip = superToolTip4;
this.cBtnFilter.TabIndex = 39;
this.cBtnFilter.Click += new System.EventHandler(this.Filter_Click);
The attached image is an example of when it is selected and when it is hovered respectively.
At the least if I could completely remove the blue line or change it to the theme color. It would be great.
Am using Devexpress Version 20.2.4
how I solved this is by using the simple button instead and making it act like a toggle button.
this method handles the toggle for me
public Boolean buttonState = false;
private void ToggleButton()
{
if (buttonState)
{
simpleButton.Appearance.BackColor = Color.Red;
buttonState = false;
}
else
{
simpleButton.Appearance.BackColor = Color.White;
buttonState = true;
}
}
this is the button
private void simpleButton_Click(object sender, EventArgs e)
{
ToggleButton();
}
here is the button in Designer.cs
this.simpleButton1.AllowFocus = false;
this.simpleButton1.AppearanceHovered.BackColor = System.Drawing.Color.Teal;
this.simpleButton1.AppearanceHovered.Options.UseBackColor = true;
this.simpleButton1.Location = new System.Drawing.Point(524, 214);
this.simpleButton1.LookAndFeel.SkinName = "The Bezier";
this.simpleButton1.LookAndFeel.UseDefaultLookAndFeel = false;
this.simpleButton1.Name = "simpleButton1";
this.simpleButton1.ShowFocusRectangle = DevExpress.Utils.DefaultBoolean.False;
this.simpleButton1.Size = new System.Drawing.Size(157, 150);
this.simpleButton1.TabIndex = 2;
this.simpleButton1.Text = "simpleButton";
this.simpleButton1.Click += new System.EventHandler(this.simpleButton1_Click);
Its quite straightforward. In case anyone has a better way or has need for this, knock yourself(ves) out.
Hopefully in the future, Devexpress will not force blue borders on us.

How to generate a button exactly NEXT TO another button?

I created separate class with custom button, which i want to be poped when this "newButton" is clicked.
How do i do it manually? so if there is multiple "newButtons" and i want to hide previous apeared Custom Buttons
My problem is that i dont know how to seek locations of the new buttons because it is in flowLayout which puts them automatically.
Button newButton = new Button();
newButton.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(50)))), ((int)(((byte)(175)))), ((int)(((byte)(241)))));
newButton.FlatAppearance.BorderSize = 2;
newButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
newButton.Font = new System.Drawing.Font("Arial", 10.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
newButton.ForeColor = System.Drawing.Color.White;
newButton.Location = new System.Drawing.Point(158, 288);
newButton.Size = new System.Drawing.Size(150, 38);
newButton.UseVisualStyleBackColor = true;
newButton.Text = k.grp;
newButton.Click += (sender, e) => newButton_Click(sender, e);
if (checkinNames.Contains(newButton.Text))
{ }
else
flowLayoutPanel5.Controls.Add(newButton);
checkinNames.Add(k.grp);
You can't achieve it by specific property directly in FlowLayoutPanel. All visual controls placed in it will automatically adjust their positions according to the size of the FlowLayoutPanel.
Here is a workaround via setting button border, backcolor, text and enable.
private void HideButton(Button button)
{
button.BackColor = this.BackColor;
button.Text = string.Empty;
button.TabStop = false;
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;
button.Enabled = false;
}
Hope this can help you.

Adding comboboxes with a function to be called by a buttonpress

So my problem is that I want to add comboboxes to a windows forms based program by clicking on a button. What I have now is:
private void addCoworkerBox()
{
DDLList.Add(new ComboBox());
comboBoxInit(coworkerIndex);
coworkerIndex++;
}
and:
private void comboBoxInit(int i)
{
var yValue = DDLCoworker.Location.Y;
DDLList[i].DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
DDLList[i].Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
DDLList[i].FormattingEnabled = true;
yValue += 34;
DDLList[i].Location = new System.Drawing.Point(380, yValue);
DDLList[i].Name = "comboBox";
DDLList[i].Size = new System.Drawing.Size(121, 28);
DDLList[i].TabIndex = 2;
DDLList[i].Items.AddRange(names.ToArray());
DDLList[i].Show();
}
the list DLLList, the int yValue and the int coworkerindex are initialized further up in my code.
I know that this is kind of a repost, but the answers to the others don't seem to help me.
The above code does not work. When I press the button that should add the new combobox, nothing happens. I have added a function for said button, that calls the addCoworkerBox() function.
You've created it just fine, but you've not added it to the form. There's a collection of controls - you need to add it to that...
Controls.Add(DDLList[i]);

Ok and Cancel Button Not showing

Why my Ok and Cancel Button are not showing up on the UI screen? I see the form, the label and the text box but I can't see the Cancel and OK buttons.
To give you a background I am creating this dialog box programmatically and all I need a a couple of text boxes , and their labels of course. And an OK and Cancel button .
All these sizes that I have used here is by trial and error as I am not much experienced in the UI control area of Visual C# 2010.
public void function x ()
{
var fileNameDialog = new Form();
fileNameDialog.Text = "Save New Name";
Label fileLabel = new Label();
fileLabel.Size = new System.Drawing.Size(150, 40);
fileLabel.Text= "Enter Person Name";
fileNameDialog.Controls.Add(fileLabel);
TextBox fileTextBox = new TextBox();
fileTextBox.Location = new System.Drawing.Point(fileLabel.Location.X + 300, fileLabel.Location.Y);
fileTextBox.Size = new System.Drawing.Size(220, 40);
fileNameDialog.Controls.Add(fileTextBox);
fileTextBox.TextChanged += TextBox_TextChanged;
fileTextBox.Text= textboxValue;
Button okButton = new Button();
okButton.Visible = true;
okButton.Text = "OK";
okButton.Location = new System.Drawing.Point(fileTextBox.Location.X, fileTextBox.Location.Y - 80);
fileNameDialog.Controls.Add(okButton);
okButton.Click += new EventHandler(okButton_Click);
Button cancelButton = new Button();
cancelButton.Visible = true;
cancelButton.Text = "Cancel";
fileNameDialog.Controls.Add(cancelButton);
cancelButton.Click += new EventHandler(cancelButton_Click);
cancelButton.Location = new System.Drawing.Point(fileTextBox.Location.X+50, fileTextBox.Location.Y - 80);
fileNameDialog.ShowDialog();
}
Your fileTextbox.Location.Y is zero, so subtracting 80 puts in above the form.
Try fileTextBox.Bottom + 4 or something like that.
Using the designer to create this dialog form is probably the better route to take. Along with the placement of the controls, you can use Anchors to make the controls relate to the size of the form.

dynamic radio button text alignment

When i add a radio button in visual c# the text name of the radio button is aligned perfectly to the right . if i create a radio button dynamically and give it several properties etc.. when i debug and view it, the text or name of the radio button is shifted slighted up and to the right of the radio button? i am looked over several properties including padding etc.. but i am not able to figure out how to correct this dynamically. what is going on and how can i fix this?
here is example of the properties i am using right now
radio_ip_addresses[i] = new RadioButton();
radio_ip_addresses[i].Name = "radio_" + i;
radio_ip_addresses[i].Text = ip_addresses.Dequeue();
radio_ip_addresses[i].Location = new Point(x, y);
radio_ip_addresses[i].Font = new Font("Microsoft Sans Serif", 8, FontStyle.Bold);
radio_ip_addresses[i].ForeColor = Color.White;
radio_ip_addresses[i].TextAlign = ContentAlignment.MiddleLeft;
radio_ip_addresses[i].Visible = true;
radio_ip_addresses[i].Parent = this;
Thanks Rotem, i took your suggestion to check the designer.cs i should have thought of that. it was autosize that was the key :), see below from what i found in the designer.cs.
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(192, 50);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(85, 17);
this.radioButton1.TabIndex = 71;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "radioButton1";
this.radioButton1.UseVisualStyleBackColor = true;

Categories