Formating the content/properties of a Winform PropertyGrid - c#

(1) Is it possible to format/change the font/color of a particular porperty name in a Winform propertygrid?
In the following example on property name ("Cursor") is red:
(2) Is it possible to change the order of categories or are they fixed alphabetical? in my case I want to have one particular category on top.

You can always set Font for the propertygrid, try this:
propertyGrid1.Font = new System.Drawing.Font("Times New Roman", 20f);
Also you can set PropertySort for it which will mimic its original behavior (like the one in the VS). Check this link

Related

Winform label control text changes place

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).

How do you highlight the field in rdlc report if changed from previous row?

I'm creating a report based on an audit table, and I want to highlight the field that has changed since the previous revision.
Try using the Previous Function, in the field properties, select font and set a formula for bold style should be something like
=IIF(Previous(Fields!myField.Value) = Fields!myField.Value, Default, Bold)
This should solve your problem you can find the documentation here Previous Function (Visual Studio Report Designer)
I wound up using something similar to what you suggested.
In the BackgroundColor property of the textbox, I used the following code.
=IIf(Fields!Revision.Value=1,"Transparent",IIf(Fields!ReasonID.Value=Previous(Fields!ReasonID.Value),"Transparent","LightGrey"))
Basically if revision = 1, it is the first revision so it is transparent (no highlighting), that is the true portion of the first iff.
In the else section of the first iff I checked if the value of the field was the same as that of the previous value of the field, if true, I set the background to transparent (no highlighting), in the else section I set the background to light grey.
This had the desired effect of highlighting in grey all field that had changed from the previous row.
Thanks

To make a specific line from a set of lines bold in a textbox/listbox

I need to make a specific line in textbox/listbox bold in C# . net and not the entire box contents ok.
Below is the example, consider that these all are displayed in text/list box,
Hi
Hello
How are you
You could note that hello is bolded, this is what I need to achieve.
Kindly help me to achieve this.
Thanks in advance.
You can use Font class to achieve this.
there is a constructor for Font class which takes following 3 attributes:
1.FontFamily : you can assign any specific font family if you want , otherwise just provide the current TextBox font Family.
2.Font Size: you can assign any specific font sie as a float number if you want , otherwise just provide the current TextBox font size.
3.Font Style: there are basically different Font Styles are available.
Like Regular,Bold,Italic,Underline,Strikeout.
You need to send FontStyle.Bold to make your text Bold.
From MSDN :
Defines a particular format for text, including font face, size, and
style attributes. This class cannot be inherited.
Try This:
Font font = new Font(textBox1.Font.FontFamily, textBox1.Font.Size, FontStyle.Bold);
textBox1.Font = font;
EDIT: as you said in below comments , if you want to make the only part of the text as BOLD its not possible in TextBox
From #Stephan coments :
but in ListBox it is possible if you use DrawItem event.
See Here : DrawEvent
as an alternative You can use RichTextBox
Solution 2: Making part of Text Bold in RichTextBox
if you are using RichTextBox control you can use SelectionFont property to make only selected Text bold (or whatever font you want to apply)
Font font = new Font(richTextBox1.Font.FontFamily, richTextBox1.Font.Size, FontStyle.Bold);
richTextBox1.SelectionFont = font;
Here is the solution...
The only list-type Control in Windows Forms that supports setting the Font property for each Item is the ListView. Try this:
put a ListView on the Form. Set its View property to Details.
edit the ListView Columns collection: add one Column; set that Column's width so its contents will be clearly visible.
// define two font-faces, one bold
private Font font1 = new Font("Arial",9.0F, FontStyle.Regular);
private Font font2 = new Font("Arial",9.0F, FontStyle.Bold);
// demonstrate adding Items to ListView
private void AddListViewItems()
{
// add ten Items
for (int i = 0; i < 10; i++)
{
var lvItem = new ListViewItem("item " + i.ToString());
// make every other item use the bold font-face
lvItem.Font = (i % 2 == 0) ? font1 : font2;
listView1.Items.Add(lvItem);
}
}
If you want to use a ListBox, you can accomplish that by drawing the items yourself.
Set the DrawMode to OwnerDrawFixed and handle the DrawItem-event. Here you can specify the the Font that is used. As mentioned in another answer, you can set FontStyle.Bold
MSDN-Example

How to change bar chart value on each bar to custom value?

Though I have values on the asp graph as attached, what I need is a different value to be shown on each bar.
For example instead of 5 on the bar graph I need to display 50 (instead of the label that displays 5).
What I would like to know is what property like the one below should i use in order to manipulate the label shown on each bar.
Chart1.ChartAreas[0].AxisX.TitleFont = new Font("Times New Roman", 11f);
Thanks in advance.
The value for the label can be set as below:
Chart1.Series["Series1"].Points[counter].Label = "2";

using visio to automate drawing diagram with c# - can't set custom properties

I have data I am grabbing from a database, and I want to use those values to populate properties on shapes on a visio diagram. I open my own template, and display shapes on the sheet with no problem. My server icon has custom properties such as "manufacturer", "network", etc. When I print out the custom properties for each shape, I get the following output:
Shape = server Label = Manufacturer Value = 0
etc. This is all correct since I haven't set any values yet. When I go to set the values, using the code in the Visio 2003 SDK (SettingACustomProperty.cs) I get an error that "this shape does not have a custom property with the universal name of Manufacturer" - yet printing out the custom properties clearly shows it does (as does looking at the shapeSheet once the shape is drawn in Visio). I've inserted to how I call SettingACustomProperty. Can someone help me figure out what I need to do to insert values into my custom properties on a shape?
Here is how I am calling the code (for testing purposes I have inserted strings myself):
string keyword = "Manufacturer";
string manuValue = "\"Dell\"";
string three = SettingACustomProperty.SetCustomPropertyFormula(visioStarShape, keyword, manuValue);
Visio custom properties have three different concepts which can be considered a name.
The first is the label. This is what you generally see in the user interface and is stored in the label cell in the custom property row in the shapesheet. The label is generally not used to access the custom property programmatically.
The second is the row name. This is the name you will see when looking at the custom property row in the shapesheet. It will appear to before the other cells in the row and be prefixed with "Prop." This is the accessed through automaton using the Name property of the custom property row .
The final row name is the universal name. The universal name exists primarily to allow code find specific Visio objects by name even after the name has been changes when the object is localized, i.e. the name have been translated. The universal name can be accessed using the NameU property of the custom property row. To learn more about universal names see Using Universal Names and Syntax to Localize Your Visio Solutions
When you call SetCustomPropertyFormula the second argument must be the universal name. This is because internally SetCustomPropertyFormula uses get_CellsU which finds a custom property cell using the universal name of the row. I suspect that you are either using the label or the row name, not the universal name, when calling SetCustomPropertyFormula.
If you are using the label you need to switch to using the universal name.
If you are using the name then it no longer matches the universal name. This may happen is some circumstances when you rename the row. You could find out the universal name and then use it in your code. The VBA immediate window is often an easy way to get the NameU property of a row. Alternatively you could update the shape or the master it was instantiated from to set the NameU property equal to the Name property and then you will avoid this confusion (until you rename the row).
Kathy: You can find out the name you need to use
Debug.Print visioStarShape.Section(visSectionProp).Row(0).NameU
Add "Prop." before this name to use it in your code.
Alternatively, with the shape selected, you can show the ShapeSheet by clicking this button in the developer toolbox
You see something like this. Look for the Custom Properties section where you see the labels and the name of your properties:
Then, you use this name to refer to the property (that's your keyword string).
keyword = """Prop.CustProp1"""
or....
keyword = "\"Prop.CustProp1"\"
Still, you don't need the SettingACustomProperty.cs file, since you can reference all the cells in the shape's sheet from your VBA code.
It is possible for you to get or set the formula in them.
See if this serves your purpose. It is an answer I've just posted in Office Techcenter: http://social.technet.microsoft.com/Forums/office/en-US/c837db4c-b90c-4500-b8ae-8d36efca44b6/can-i-apply-custom-property-sets-from-vba-in-visio-2003
Since my system is spanish, I've changed the stencil's and master's names by guess. But the important methods are AddSection, AddNamedRow and especially for you the .Formula one (FormulaForce is the same, but it works even with cells protected with the GUARD function).
Good luck. I'm in love with Visio 2003 (I wish my company had bought Visio 2010, though) :D
'Set the value for the property: vsoShape is an object referencing the shape
vsoShape.Cells("Prop.CustProp1").FormulaU = """Hello"""
vsoShape.Cells("Prop.CustProp2").FormulaU = 2556
The type of CustProp1 is string, and that of CustProp2 is number.
Regards,

Categories