Check Box Label Above Checkbox. How? - c#

I am using C# visual studio 2010 to develop an ASP.NET website.
I dynamically create a checkbox at run time.
CheckBox chkbox = new CheckBox();
chkbox.ID = "chk" + checkboxID;
// Add our checkbox to the panel
dynamicPanel.Controls.Add(chkbox);
chkbox.Text = checkboxName;
By default, the label is displayed to the right of the checkbox. I can successfully move the label from side to side by adjusting chkbox.TextAlign = TextAlign.Right / Left.
What I can not figure out for the life of me is how to set the Text above the check box.
I am not looking for any kind of hack like, verticle-align:-3px as this will not work for me because I let the user pick the font and size of the text. It will not always be -3px in depth.

I suppose you should go with a new Control where you add a separate Label below the Checkbox (actually wrapping the checkbox).
Derieve that class from CheckBox, and override (or define new if not virtual) the Text property, so it will now set the upper Label's text.
This will actually be a good example of Decorator pattern.

Set the text align property to TextAlign.Left then use CSS to set the label's display to: block.

Related

Accessibility in TextBox in Windows Form - Visual Studio

I'm new to visual studio and I'm developing an application for visually impaired. I'm testing my application with NVDA. The audio feedback I'm getting on moving focus to a TextBox using tab button is just "Edit-Blank". I want to change that to a custom text. How can I do that?
That has nothing to do with accessibility, actually. When developing for accessibility, please always keep in mind the following: a blind (deaf, ...) user must get the same info as all of your users, starting from yourself, unless you absolutely need to convey something that is inaccessible otherwise (a visual tooltip instead of a sound for deaf users, an alternative text description of an image for blind users, etc.).
Here NVDA tells you what you actually get: the edit box is blank, indeed. If you want to describe the box, you need a label, not something in the text box (let the user enter his/her text in it). So:
private Label myLabel;
// ...
this.myLabel = new Label();
// ...
this.myLabel.Text = "Your Name:";
and place that label to the left (or above) the edit box. You may also set AccessibleRole, if you want:
this.myLabel.AccessibleRole = AccessibleRole.StaticText;
I suggest to do this if your form is actually a dialog box.
You need to put a Label control into the form and update the TabIndex properties of the Label and TextBox, so that the Label's TabIndex value is one less than the TextBox's TabIndex value (e.g. label1.TabIndex == 1 and textBox1.TabIndex == 2).
Then, the Text of the Label will be read when entering the TextBox.
To make a TextBox more accessible by NVDA you can perform either of the following settings:
You can set AccessibleName
You can set AccessibleDescription
You can put a Label control near the TextBox having immediate TabIndex before the TextBox.
For Narrator you can perform either of the following settings:
You can set AccessibleName
You can set Cue Banner for the TextBox.
You can put a Label control near the TextBox having immediate TabIndex before the TextBox.

Aligning controls inside cells of a TableLayout

In the picture below I have defined a 6-row table layout and placed controls inside its cells, in one cell goes the Label, the other cell for the control its self (a text box for example )
The problem is caused by that field options radio box, it will make the cell so big so then the text box that is under "Preview Data Value" label, goes way below...
How do you suggest fixing this issue?
From my prior experience, I would not use the table layout at all. Instead I would set the anchors on each control to dynamically change with resize.
But if you insist on using the table layout, perhaps you should change the RowSpan attribute of the Preview Data Value cell, and have the label at the top with the text box underneath.
Another option would be to use a container like a GroupBox with a title Attribute that you can set to "Preview Data Value", put the text box in that container and set the "Dock" Attribute to "Fill". Then from the looks of it, you don't even need the last Row.
See this article on MSDN if you want to go totally nuts and implement your own drawing.
Make a seventh row and have the option group span two rows.

Read only combobox?

How do I make a combobox read only? I remember back when I used VS2005 you could have a read only combobox in the default style. Reason I don't want to use DropDownList is because it looks ugly on forms that don't use a default color. Here is an example.
I want one like in the left of this picture.
Were you can not enter in your own text. But I don't want the style in the first image to the right.
Set the drop down style to DropDownList and the flatStyle to Flat:
this.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
this.comboBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
You can select always the element[0] (if exists) to look like the example you provided.
The Visual Studio combo draws a border OnMouseHover, you can also do this if you want.
Change the drop down style, it's a property.
See: http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.dropdownstyle.aspx

Make the text of a disabled textbox easier to see

I have a text box that when it is disabled the text in it is gray and kind of dithered. (This is the standard functionality.)
Is there a way to make this easier to see?
I have tried this:
txtBoxNumber.Enabled = false;
txtBoxNumber.ForeColor = Color.Black;
and that has no effect.
NOTE: This is a .net Compact Framework app, but I am not tagging the question with CF because I think it is the same for normal .net.
txtBoxNumber.ReadOnly = true;
// Then set your styles here...
HTH.
Why don't you make the TextBox.ReadOnly instead? That would allow the user to see & copy the textbox value, but not change it. A read-only textbox is usually rendered the same way as a normal textbox.
From MSDN:
You can use this feature instead of disabling the control with the Enabled property to allow the contents to be copied and ToolTips to be shown.
I often set it to read only or if you have to use disabled set the text box color to white and the font color to black.
Just make the text box Read-Only. And then if you need to set style, set it.

Disable check/uncheck CheckBox after clicking checkbox`s label

How can I disable standard behaviour when choosing checkbox`s label. Now when I click on label checkbox change its state.
Thanks
you could have a check box with no text and then a label next to it.
You could wrap this up in a user control / control to make things a little neater.
This is inherent behavior. You can pass empty string as label text and put a label beside checkbox. Or you can create composite control with Checkbox with empty text and a label with the text intended for checkbox's label.

Categories