|
Yes, it can be easily done in a rich text box. Please read the following example.
The following example displays a ColorDialog to the user to specify a color for the current text selection or text entered after the current insertion point in a RichTextBox control. This example assumes that the method defined in the example is added to a Form class that contains a RichTextBox control named richTextBox1.
[Visual Basic]
Public Sub ChangeMySelectionColor()
Dim colorDialog1 As New ColorDialog()
' Set the initial color of the dialog to the current text color.
colorDialog1.Color = richTextBox1.SelectionColor
' Determine if the user clicked OK in the dialog and that the color has
' changed.
If (colorDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
And Not(colorDialog1.Color.Equals(richTextBox1.SelectionColor)) Then
' Change the selection color to the user specified color.
richTextBox1.SelectionColor = colorDialog1.Color
End If
End Sub
[C#]
public void ChangeMySelectionColor()
{
ColorDialog colorDialog1 = new ColorDialog();
// Set the initial color of the dialog to the current text color.
colorDialog1.Color = richTextBox1.SelectionColor;
// Determine if the user clicked OK in the dialog and that the color has changed.
if(colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
colorDialog1.Color != richTextBox1.SelectionColor)
{
// Change the selection color to the user specified color.
richTextBox1.SelectionColor = colorDialog1.Color;
}
}
Regards,
Sugandh
|
|
|
|
|
Hi there,
I've used the following string to create a multiline string.
String str = "line1 \n newline2 \n newline3";
but I didn't get the appropriate result. I got something like this:
line1 newline2 newline3
How can I create multi line string?
thank you in advance.
|
|
|
|
|
Try replacing '\n' with line feed '\x0a' and carriage return = '\x0d'
|
|
|
|
|
I think you cannot save the currage return functionality in a string.
Try Console.WriteLine("line1\nnewline2\nnewline3");
or
String str1 = "line1";
String str2 = "newline2";
String str3 = "newline3";
Console.WriteLine(str1 "\n" str2 "\n" str3 );
hope this helps
|
|
|
|
|
Use "\r\n" instead of just "\n"
|
|
|
|
|
|
|
Hi,
Option 1:
string str = "line1" + "\n" + "newline2" + "newline3";
Option 2:
String str = "line1 \n\r newline2 \n\r newline3";
Majid, Tell me if these does not work.
Regards,
Sugandh
|
|
|
|
|
non of them doesn't work Sugandh.
I wanna use it in header text of a column of DataGrid control.
|
|
|
|
|
What do you think "multi line strings" are?
For the String class, the character '\n' is handled exactly like an 'a' or '7'. It's just a character like any other. String itself doesn't have a concept of multi line!
So you'll have to tell us where you want to _use_ the string.
In a TextBox , the line separator is "\r\n".
In a RichTextBox , the line separator is "\n".
So depending on where you need the string the answers will be different.
mav
|
|
|
|
|
I wanna use it in the header text of a column of DataGrid control.
|
|
|
|
|
Then I would guess it is the DataGrid that strips the newlines.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
In this case I doubt that you'll succeed with any of these approaches.
You see, the DataGrid is responsible for drawing the column headers according to their current texts, but I don't think the developers took multiline headings into consideration.
That's why you get blanks where your not-printable characters ('\n', '\r') are.
In order to achive multiline headings you'd have to perform drawing of the DataGrid column headers by yourself (perhaps you're able to do this using P/Invoke, I'm not sure).
Anyway: My suggestion would be _not_ to use multiline headings. Headings are used to give the user a short information what the contents of a column are. You're not supposed to write lengthy texts there.
mav
|
|
|
|
|
I am trying to develop the following functionality. The user selects a button. In the on-click event I then want to bring up a new web page (small one) that contains a dropdowm list box. This list box would be bound to a data base. When the user selects an item the page disappears. I then work with the data that was selected.
How do I do this?
Thanks in advance
|
|
|
|
|
Try the ASP.NET[^] forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi.
Any of you have an working exampel of the function mmioInstallIOProcA??
|
|
|
|
|
Never mind..... made it work.
But thanks anyway.
|
|
|
|
|
I want to track the mouse position by drawing a line or cross at the location of the pointer.
What I can't figure out is how to erase the previous location from the display.
In other languages I would have done used a XOR pen but I can't find the same thing in C#.
I want the behavior to be something similar to the tracking line when panels are resized.
Thanks,
Eric
|
|
|
|
|
Hi, Im having trouble creating an rtp header at the moment as I need to convert a short into a 2 bytes for the sequence number!
I have tried going to an string them byte but this then produces 5 bytes not 2! and also using the Convert class but this only converts to a single byte!
How do I go about this?
Many thanks, Mat
|
|
|
|
|
Try BitConverter.GetBytes
|
|
|
|
|
Hi!
I am wondering about the c# code-technique "using".
As I understand, when the program leaves the using-block, the resourse defined whith the statement is disposed. In that case the two cases below should be identical:
//*** Case 1: (without myConnection.Close()) ***//
using(SqlConnection myConnection = new SqlConnection(sConnectionString))
{
SqlCommand myCommand = new SqlCommand("GetUsers", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
//Fetch data
}
//*** Case 2: (with myConnection.Close()) ***//
using(SqlConnection myConnection = new SqlConnection(sConnectionString))
{
SqlCommand myCommand = new SqlCommand("GetUsers", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
//Fetch data
myConnection.Close();
}
Can anyone confirm that there is no defferences between the who. Case 1 just seems a bit dangerous to me
Thanx!
/Paul
|
|
|
|
|
I think you are asking two questions:
1.
using (SqlConnection myConnection = new SqlConnection(sConnectionString))
{
}
is equal to
SqlConnection myConnection;
try {
myConnection = new SqlConnection(sConnectionString);
} finally {
if (myConnection != null)
myConnection.Dispose();
}
This works good and you can trust in it
2. The other question is if a Dispose call on a SqlConnection is going to close it and yes it does.
|
|
|
|
|
Hi
I want to write a program that use notifyicon but i don't want to use a form container . i create a console aplication and use a notifyicon !
everything was well but my icon does not responce events ?
my goal is to prevent showing a form and reduce memory usage .
how can reach this ?
Thanks Amir Jalaly
|
|
|
|
|
|
Hello,
I have a C# WMEncoder application which is using a C++ transform plugin(DirectShow), I would like to send additional information to the filter and recieve information from the filter.From the filter I can use the SendMessage() function, but how can I send information to the filter?
I tried to create another c++ com, where I give it the IUnknown of the filter(thru a property of the com I created) and use the QueryInterface() method(in a method called SetEvent() I created in the com) inorder to use the IMyInterface of the filter but I get an error trying to use it in C#:
"Object reference not set to an instance of an object"
|
|
|
|