Winform label control text changes place - c#

I have a
labelControl.Text ="My name:";
Result is
:My name
Symbols changes place.
If I write "&= My name", the result is =& My name.
How do I stop it from changing places?

You need to set the RightToLeft property correctly. By default this should be RightToLeft.Inherit. But either your Form or your Label was set like:
labelControl.RightToLeft = RightToLeft.Yes;
You need to set it to RightToLeft.No or RightToLeft.Inherit (if the parent control has it set to No).

Related

Changing text box ForeColor and BackColor property value has no effect

Using Winform, I have a textbox whose default value is grey, and I want it to become whitewhen I click it.
So I change the value of the property like this:
tb_OutputFileSuffix.ForeColor = SystemColors.ActiveCaptionText;
tb_OutputFileSuffix.BackColor = SystemColors.ActiveCaption;
The code is reached, the value is modified properly, but the displayed color remains white. I tried calling the Refresh method without getting more success.
What am I missing ?
Thanks

Disable first line of textbox

I made a program like notepad. I want the first line to be the date and time when the note was made. I get this with:
tbEditor.Text = Convert.ToString(DateTime.Now);
But is it possible to disable this first line so the user can't delete it afterwords?
Use a or to display data that doesn't require user intervention. You can use a stack with textblock and then a text box in it to store date and user note respectively. Alternatively, if you want to use a textbox, you can set IsReadOnly property to true OR IsEnabled property to false. But this is not just for the first line, but for the whole textbox. So you would need a separate control to store the Date and Time

Hiding a single control on a Details Section in ActiveReports

I'll try to simplify the situations as much as possible.
I have an ActiveReports subreport that has a control which I fill using FetchData event. Sometimes I need to hide the control if its blank or in this occassion the value is Cotton but Polyester should appear. The problem is that when I hide a control, it hides the control on every occurrence in the report not just one instance that so need. Is there something I'm doing wrong.
I define the control in InitializeReport
Material1 = DirectCast(Detail.Controls("Material1"), Label)
Material2 = DirectCast(Detail.Controls("Material2"), Label)
I set up the Datafield for the control in the DataInitialize event
Fields.Add("Material1")
Fields.Add("Material2")
In the FetchData event, I fill the control, so three records, the control gets populated appropriately. There's nothing wrong. If the second record has a value then thats fine. e.g.
1st Record, first call of the FetchData event.
Fields("Material1").Value = "Polyester"
Material1.Value = "Polyester"
Fields("Material2").value = "Wool"
Material2.Value = "Wool"
2nd Record, second call of the FetchData event.
Fields("Material1").Value = "Cotton"
Material1.Value = "Cotton"
Fields("Material2").Value = "Wool"
Material2.Value = "Wool"
If I want to hide the second record/control from being seen, after the control is filled, I hide the control in the Details_Format event, however, it hides all three Material controls rather than just the one individual instance. What could I be doing wrong?
If Fields("Material1").value = "Cotton" then
Material1.Visible = false
End if
I want wool to appear twice, in both records but Cotton to not appear in the second grouping. I just can't hide the Cotton controls. I don't want to simply blank out the Material1 because I need to hide the control so that I can move controls up and reorganise the report. There is a label beside Material1 which I hide as well as the Material1.
VB or C# solution please.
You need to add Else to you If or replace with
Material1.Visible = Not (Fields("Material1").Value = "Cotton")
that way it turns on or off based on the value. When you set the property you're setting it on the instance for the whole control, the subreport has only one instance not one for each detail.
hope this helps.

Number Format For Datagridview in C#

I want to set the datagridview values in number format. Currently I am getting this:
I want something like this:
I have used this code:
dgvmain.DefaultCellStyle.Format = "#.##0";
And this code
dgvmain.Columns["Amount"].DefaultCellStyle.Format = "#.##0";
But neither of this working.
You can Set you Format String using CellStyle Builder an set the Custom format to # mm
How to do it :
Right click on Grid, then Properties
In the property window, click the button that will popup up the Edit Columns Dialog
Select the cell you want to format
On the right side of the Edit Columns Dialog select the DefaultCellStyle property Click the DefaultCellStyle property, then the CellStyleBuilder dialog will open Here you have
the format property, this will give you the Format String Dialog
Set the Custom property to N2 you will see the preview at the bottom
Click OK ... till you are back to your Grid...
If you want to do it from Code, put this code inside Form_load event.
dgvmain.Columns["Amount"].DefaultCellStyle.Format = "N2";
Goto your Form's Design mode then goto the properties of dgvmain there check DefaultCellStyle and set the format as you like.
OR
you can do this
dgvmain.Columns["Amount"].DefaultCellStyle.Format = "N2";
:)
You have to spot, that all the data on your first screenshot are left aligned.
The formatting you try, and the others adviced are good. I must note, DefaultCellStyle most be used before you add columns to the grid.
The case, that it seems specified formats does not work, tells me your data type may be string, not numeric.
Try
dgvmain.Columns["Amount"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

Change label to textbox for edit

Have a look at this example first,
click here. I want you to see only the example of how he changed a label into text box after he hits edit.I want to make edit profile page but I don't want to use bind grid view. Is there any possible ways to retrieve some data from table in database to be shown in labels then when uset hits the edit button, the label will change to textbox?
why do you need to show a label ?
you can show it in a text box and set IsReadOnly or ReadOnly to true, set style to flat and remove border(it'll appear like a label), and then on the Edit Action, you can change this ReadOnly/Editable property.

Categories