|
i tried the stringbuilder and got the same results
public override string Text
{
get
{
return base.Text;
}
set
{
ColorAnsiString(value);
}
}
public void ColorAnsiString(string s)
{
StringBuilder str = new StringBuilder(s.Length);
Color col = colors[(int)ColorCodes.BLACK].Col;
int i = 0, x = 0, y = 0, n = 0;
for(i = 0; i < s.Length; i++)
{
if(i > s.Length || i+1 > s.Length)
break;
if(s[i] == '&')
{
if(i+1 < s.Length)
{
if(s[i+1] == '+')
{
for(x = 0; x< (int)ColorCodes.MAX; x++)
{
if(s[i+2] == colors[x].Key)
{
col = colors[x].Col;
break;
}
}
}
}
for(n = 0, y = i+3; y < s.Length; y++, n++)
{
str.Append(s[y]);
if(s[y] == '&' || s[y] == '\0' || s[y] == '\n' || s[y] == '\r')
{
//str += '\r';
base.Text = str;
//this.Select(base.Text.Length-str.Length, base.Text.Length);
// SelectionColor = col;
// i+=str.Length;
//
// col = colors[(int)ColorCodes.WHITE].Col;
return;
}
}
}
}
}
if you replace base.Text with s it works when its str it doesnt
|
|
|
|
|
Do not use \r, \n, or \r\n but Environment.NewLine . That will always return the correct line ending for text on the current platform.
Also, what exactly are you trying to do? As I've been trying to get from you this whole time, your code isn't necessarily wrong but what you're attempting to do may be. The RichTextBox.Text property is plain text with only new line and tab characters being supported as the only "format" characters. If you're trying to encode text with color information you need to be modifying the RichTextBox.Rtf property.
Since you're replacing - or at one point was replacing - character with invalid escape sequence the RichTextBox (rather, the Rich Edit common control that is encapsulated) is most likely rejecting the text completely. Immediately after setting base.Text use Marshal.GetLastWin32Error() and compare that with what you see in teh documentation for the Rich Edit Message reference online at http://msdn.microsoft.com/library[^]. You may actually have to look at the headers (installed with VS.NET by default, but you can download them from http://msdn.microsoft.com/platformsdk[^] to see what those error values correspond to.
You should also use a decompiler like .NET Reflector (google for it) to see how the RichTextBox actually sets the text.
Whatever text you're giving to the RichTextBox.Text property is not acceptable, which is what I've been trying to get you to see. The code itself is fine, and my suggestion about using StringBuilder was not to fix your problem but to help you avoid other performance problems with veyr inefficient code.
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]
|
|
|
|
|
im not doing any fancy text or inserting new characters im just trying to remove some characters from the original string put it in a new string and put it in the text box im just simply trying to find out why my new string isnt getting put into the text box yet my original one shows just fine if i use it instead of the new one
|
|
|
|
|
i just tried to do base.Text = "hello" and this doesnt even work or if i modify the string that was passed that doesnt work either
|
|
|
|
|
I am trying to iterate over an array and grab performance values for each value in the array.
For instance:
public void getstuff()
{
string[] computers = {"coruscant", "tatooine", "alderran"};
foreach ( string comp in computers)
{
try
{
this.performanceCounter2.MachineName = comp;
string cpu =performanceCounter2.NextValue().ToString();
}
catch ( Exception e)
{
MessageBox.Show(e.Message);
}
The thing is im looking for an exception of sort so that if the node is not available/perf service stopped) it just moves along to the next value. The above doesn't seem to throw an exception, but the lil app wedges up pretty hard after a few loops.
Is there anyway I can check, fairely quickly that the value exists then if it doesn't move on to the next value in the array?
sween3
--
Thank you.
|
|
|
|
|
i stored a Time field in MySQL database and the DBAdapter.Fill() use DateTime to store the return value. and, this leads to 'FormatException'.
do u know any method to do some custom datatype matching to solve this problem? or, i just go to change the datatype in database to string or other simply datatype?
thanks,
jim
|
|
|
|
|
Try to use ToString() method before passing into the database.
Eg: DateTime dt;<br />
<br />
Assume that,<br />
dt is 12-12-2004 12:24:44 Am;<br />
<br />
dt.ToString("yyyy-MMM-dd") will return 2004-Dec-12.<br />
dt.ToString("yyyy/MMM/dd") will return 2004/Dec/12.<br />
<br />
dt.ToString("yyyy-MM-dd") will return 2004-12-12.<br />
dt.ToString("yyyy/MM/dd") will return 2004/12/12.<br />
<br />
dt.ToString("mm-DD-yyyy") will return 12-12-2004.<br />
dt.ToString("mm/DD/yyyy") will return 12/12/2004.
Hope this will serve your purpose.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
He's trying to fill a DataSet , not update the database. Besides, if you specify SqlDbType.DateTime for the column type then the value should be an instance of the DateTime struct.
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]
|
|
|
|
|
There is no time type in SQL Server. If you're referring to the timestamp type then be sure to read the documentation for the SqlDbType enumeration.
A timestamp translates to a byte[] array. In SQL Server a timestamp is an automatically generated array of binary numbers that is guaranteed to be unique with a database. It is not a time portion of a DateTime or anything like it.
If DataAdapter.Fill is having trouble determining the proper type then you'll need to define the DataColumn s in your DataTable within the DataSet manually. The easiest way to do this is to create a typed DataSet using VS.NET.
You can drag-n-drop tables, views, or stored procedures from Server Explorer (i.e., from connected databases) into the designer when you create a new DataSet type. Right-click on your project (or a folder within your project) and click Add->Add New Type. Then click "DataSet", give it a name, and click OK. Now you get what looks like (and actually is) the XML Schema designer. Drag any of those objects from the Server Explorer I mentioned above onto this surface, or design the tables and fields (elements and child elements) yourself. You can even add DataRelation s and keys in this view as well.
When you compile your project a typed DataSet is created. Instantiate a new instance of this DataSet instead of the base DataSet class.
For performance improvements, use the typed table and column properties which decrease the number of required look-ups to find the correct table or column, respectively.
On the other hand, you chould change the type in SQL Server. If you intended to have a field that stores just the time, then you need to declare it as a DateTime field in SQL Server. It's your views and what you do with the data that determine if the time, date, or both matter.
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]
|
|
|
|
|
Is there any way for me to store forms that are minimized in a separate container window?
I would like the forms, when maximized to be shown on the main window form and when minimised stored in this separate container window.
|
|
|
|
|
Within your own application there's not much you cannot do. If you want to capture minimized windows from other processes that's a different matter. The Windows shell (Windows Explorer) handles this and there's not much you can do.
You could install a Windows hook using the WH_CBT (0x5) message and handling the HCBT_MINMAX (0x1) notification message in your CBTProc callback. These refer to native functionality so you'll need to be familiar with P/Invoke. Above all - be careful. Windows system hooks are hooks for messages throughout the entire system. Your code must be efficient and robust, meaning that it can fail gracefully and cleans itself up if problems occur.
For more information about using system hooks in C#/.NET, read Using Hooks from C#[^] here on CodeProject. Do be sure to read the information in the Platform SDK specifically for the WH_CBT hook for information about the callback parameter values (like which ones pass you the HWND (an IntPtr in managed code) that you can use in calls to other native APIs).
While you won't be able to stop the default behavior using this approach (and I honestly can't think of any other hooks or sinks you can use from all my experience and research), you could P/Invoke other native APIs like GetWindowText to collect information about windows and display some captioned icon in a window of your choosing.
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]
|
|
|
|
|
Suppose I have built program that can save it state in some files. I'm interested in basics on how can I register an file type to my application (when file with extension .myProj is doubleclicked my program opens and loads state from that file)... I'm using Setup for deploying application.
Tnx in advance for any idea
|
|
|
|
|
|
Hello,
In my code I'm using a ListView control with LargeImageList enabled. But I noticed that the thumbnails that display my pictures are automatically stretching my images.
In my picturebox I've scaled my images and set the sizemode to center. Now I would like the listview to display this the same way (just like they get scaled in windows explorer thumbnails)
Thanks,
Ghost
|
|
|
|
|
The icons you add to an ImageList after setting the icon size must be that size or they will get stretched. So, if you need large images set your ImageList.ImageSize to 32,32 (or whatever is appropriate) then add images of that size. If you don't, they will be stretched.
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]
|
|
|
|
|
Then how can I get scaled images into the imagelist. I want all imagelist images to have the same size but not necessarily completely filled.
Eg: My ImageList.ImageSize is 60,60 and I have 2 images that I need to fit in this imagelist, that have a size: 60,40 and 30,60. Still I want the LargeImageList to keep displaying square images with those 2 scaled images without being stretched.
It should be possible, windows explorer does it this way.
I could solve it by making a 60,60 bitmap, filling the center with my 60,40 image and fill the rest with white pixels, but that seems like a way to create overhead...
No other possibility?
greetz,
Ghost
|
|
|
|
|
You need to scale them first. Create a Bitmap of the appropriate size, then get a Graphics object from the Bitmap using Graphics.FromImage . Use Graphics.DrawImage to draw and scale the image in the Bitmap . When finished, call Graphics.Dispose and add the new Bitmap into the ImageList .
If you want to draw a certain color for a background, use Graphics.Clear and specify a color like Color.White .
What Windows Explorer does is much more complicated than you think. Windows Explorer doesn't really even do much in regards to what you see and your question: it's shell extensions that handle this and how they do it depends on their implementation. What I described above, however, is basically what most such extensions do (only using managed code in this case, instead of GDI or GDI+).
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]
|
|
|
|
|
Thank you for the quick answer,
Ok, I'll solve it that way: scale it and fill the rest with white pixels.
Just find it strange though that they did not provide a sizemode for an imagelist, the same they provided it for a picturebox.
Greetz,
Ghost
|
|
|
|
|
geestje wrote:
Ok, I'll solve it that way: scale it and fill the rest with white pixels.
Actually you'll want to clear it and fill it with white pixels first (you can do that with one call; read about Graphics.Clear ) then scale and draw your image.
It's not weird at all if you understand what these objects actually are. A PictureBox draws an image into an HDC for a window (a control is a window in native terms). An ImageList is a wrapper around a native GDI+ ImageList that draws whatever you give it into an HDC for the images it contains. It is meant only to hold images - not to display them to users. It is the control that uses the images that defines how those images are drawn. Think of it as a simple collection.
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,
I had to create my own form to get files from my directory because i had to add allot of functionality not available on the system dialog boxes (done with that) now my problem is i need to pass on the selected files from my directory form to my main form...i can't get this to happen...can anyone help??...this is how i'm calling my second form:
private void mnu_Open_Click(object sender, System.EventArgs e)
{
Form2 myMenu = new Form2();
Menu.Show();
}
|
|
|
|
|
If I understand you correctly, you can have property ( or internal field) with data you want to pass...
It can look like :
<br />
class Form2:.... {<br />
...<br />
<br />
public string[] Files<br />
{<br />
get<br />
{<br />
return m_files;<br />
}<br />
}<br />
}<br />
<br />
private void mnu_Open_Click(object sender, System.EventArgs e)<br />
{<br />
Form2 myMenu = new Form2();<br />
<br />
myMenu.Show();<br />
<br />
DoSomethingWith(myMenu.Files);<br />
}<br />
Does it help?
bets regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
And out of mercy to those who might have to read your code, you might want to use a more meaningful name than "Form2" for the thing. As well, myMenu = new Form(); is a bit confusing -- is it a form or a menu?
Additionally, you might want to use ShowDialog() and also set the dialog result values appropriately, so you can use your dialog as you would an OpenFileDialog, for example:
if( openFileDialog.ShowDialog(this) == DialogResult.OK )
{
}
Matt Gerrans
|
|
|
|
|
Matt,
I didn't ask you for your judgment i asked for some help. You unlike the other guy were of no assistance. Oh btw...I simplified the code down to a textbook manner so that i can get my point across without copying my entire file into the thread...next time give your opinion when asked for it.
|
|
|
|
|
Okay, sorry about adding the editorial. I removed that part, but I hope at least the part about the ShowDialog() and the DialogResults was helpful.
Matt Gerrans
|
|
|
|
|
You don't need to apoligize for correcting bad examples. Many times in this forum some people post bad examples that foster bad coding in other developers. Nothing leads to poor quality software than code written half-assed.
|
|
|
|