Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
C

clatten

@clatten
About
Posts
22
Topics
10
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Problem creating working XSD with restrictions
    C clatten

    I have a couple of xml files I'd like to create xsd schemas for. This is not so difficult but the problem is that the strcuture of the xml file (something I can't easily influence) is strange. The files problem section look like this: 1.0

    .jpg 128 128 65536 X Model X X1 7592597B-E087-4565-9BAC-596C096EBB2C X2 523DC659-B6F8-4b38-8EEB-B19E7AC7F2E3 1:1 TCFILETRANSFER 1 \\

    My problem is not that I can create a working schema. It is that I'd like to have restrictions on all key elements which I cannot figure out how to do since they are all of different types. For example key name="defaultImageType" has a string as value and i'd like to have a restriction xs:enumeration value=".jpg | .bmp | .gif" but I also want to have key name="imageHeight with type xs:positiveInteger and so on. Is this possible, to have different types on elements with same name? Apparently the xml file works. And if it is allowed how can I do the schema? /Clatten

    XML / XSL xml tutorial question database help

  • Specialised task manager
    C clatten

    Through googling I later found that the easiest way was to use the GetGuiResources method in User32.dll. This provides the GDI and USER objects counters for each process.

    C# performance graphics question

  • Specialised task manager
    C clatten

    Hi Heath, thanks for your answer. I did look into the performance objects in PerfMon (I have a XP Home WS at home and a Win2K WS at work) and could not find any counters for the process object. Actually I could not find any counter for this. I have looked with exctrlst.exe and could not find any disabled counters. So I have to ask if you can point me in the right direction on how to proceed: 1. Do I have to do something to add more counters to the process object (or they might just not are available in WS PerfMon). 2. Is there any other performance object I should look into (but I still want the count per process as in the Task manager).

    C# performance graphics question

  • Specialised task manager
    C clatten

    I was thinking of creating a simple, specialised task manager. It seems quite easy to use the Diagnostics.Process class to get processes memory and CPU usage. But I also need to get GDI and USER objects per process. Is there any similar class for that or is it performance counters or WMI I need to look into?

    C# performance graphics question

  • Fetch file system info
    C clatten

    Yeah, it looks promising. I'll give it a try on Monday. Have a nice weekend.

    C# question

  • Fetch file system info
    C clatten

    Hi, By fetching the logical drive from a folder I'd like to test what file system I'm on (NTFS or FAT16/32). Have tried to figure out how that is done but so far been unable to find any useful way to achieve this in neither System.IO or using ManagementObjectSearcher (WMI). Anyone that can hint me where to look?

    C# question

  • out-of-memory exception thrown when using Find
    C clatten

    Embarrassingly enough I believe the out-of-memory was due to that I dodn't took care of when there was no hit on the search. The failed to load resources probelm remains though.

    C# help algorithms performance tutorial question

  • out-of-memory exception thrown when using Find
    C clatten

    I use the code below for a simple search function in a richtextbox. When I load larger files, and try to search it will always throw an out-of-memory exception. From the debugging it seems to be richTextBox.Find that is the culprit. For an example, searching File1 that is 1800kB is no problem but File2 at 17000kB will always throw the exception. Opening File2 in, for example Notepad, and search is no problem. Anyone knows why, is there a limitation with richTextBoxes and why can I then load the file with the Loadfile function? Is there any workaround for it? I also ran into another problem, with one specific file I don't get the exception when I search but instead "Failed to load resources from resource file. Please check your setup". I use the default settings and I did run the "fix application". Still it will crash with this message. Any fix for this? try { RichTextBox.SelectionColor = Color.Black; int searchEnd = RichTextBox.TextLength; searchStart = RichTextBox.Find(searchTextBox.Text, searchStart, searchEnd, RichTextBoxFinds.MatchCase); RichTextBox.SelectionColor = Color.Blue; //RichTextBox.SelectionFont = Font.Bold; RichTextBox.GetPositionFromCharIndex(searchStart); RichTextBox.Focus(); RichTextBox.ScrollToCaret(); if ( searchStart < searchEnd ) { searchStart++; } else { searchStart = 0; } } catch (Exception f) { MessageBox.Show("Failed to search " + searchFile + "\n" + f.ToString()); }

    C# help algorithms performance tutorial question

  • Search and display text in richtextbox
    C clatten

    Embarrisingly enough I tried that first but discrded as not working. Just to find out that the control needed focus before it worked... So it was just to add richTextBox1.Focus(); richTextBox1.ScrollToCaret();

    C# question

  • Search and display text in richtextbox
    C clatten

    I want to do a simple search function in a richtextbox. I have loaded a file and by using the Find method it's possible to find a text string, highlight the string and extract the line number, but how can I programatically scroll down to the line? private int findText(string searchText, int searchStart, int searchEnd) { int indexToText = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase); richTextBox1.SelectionColor = Color.Blue; int lineNo= richTextBox1.GetLineFromCharIndex(indexToText); return indexToText; }

    C# question

  • Problems with huge files
    C clatten

    Thanks for your answer but unfortunately I have no control of the logfile. It's because it's huge and diifcult to read I'd like to build my own logfile reader. What I need most I think is a tip on how to reverse output using StringBuilder. Otherwise I do thing StringBuilder is the way to go.

    C# database debugging help question

  • Problems with huge files
    C clatten

    I am working on an app that should open a logfile and then it should be possible to: 1. output the whole file as it is 2. reverse the output 3. filter the output I am outputting to a richtextbox since I also want to highlight specific lines. I have tried both using ArrayList and StringBuilder. The latter seems better but then it is not so easy to reverse. To add all text to the RichTextBox I use RTB.Text. I have also thought of outputting all to a temp file and use RTB.LoadFile instead. The problem is that the logfiles can be quite huge, >5MB in extreme cases. This causes it to be very slow and I also encounter out-of-index problems in certain situations that I have not been able to pin down in the debugger. Could anyone advice me on the best way to get a stable and not to slow solution (since I have to work through the whole file line by line to filter it will never be quick)? Code extract: try { StreamReader sr = File.OpenText(fileName); string input = null; //ArrayList myList = new ArrayList(); StringBuilder sb = new StringBuilder(); while ((input = sr.ReadLine()) != null) { if ( Filter or not ) { Filtering of each line. If condition met then sb.Append(input); //myList.Add(input); } } else { sb.Append(input); //myList.Add(input); //myList.TrimToSize(); } } sr.Close(); //myList.TrimToSize(); if ( checkBox4.Checked ) { //myList.Reverse(); } richTextBox1.Clear(); /* for (int i=0;i

    C# database debugging help question

  • Simple XML browser
    C clatten

    Well, I was advised to use the webbrowser COM component and that was it.

    C# xml question

  • Simple XML browser
    C clatten

    I'd like to create a simple XML browser that displays a XML file an similar way as IE does. I'm not doing anything with the file, just want to display it in a readable way. I have tried with xmlreader and richtextbox classes but not really been successful in formatting the XML in a nice way. reader = new XmlTextReader(xmlfile); reader.WhitespaceHandling = WhitespaceHandling.None; // Parse the file and display each of the nodes. int curr = 0; int next = 0; while (reader.Read()) { curr = reader.LineNumber; richTextBox2.AppendText(reader.Name); richTextBox2.SelectionColor = Color.Blue; richTextBox2.AppendText(reader.Value); richTextBox2.SelectionColor = Color.Black; if ( curr > next ) next = curr; else richTextBox2.AppendText("\n"); } Is this the right way to go, or should I start looking at other solutions?

    C# xml question

  • Highlight a line that contains a string
    C clatten

    Dunno what I was thinking about yesterday since it was pretty obvious. private void onLoad(object sender, System.EventArgs e) { richTextBox1.Text = "Hello World\n"; richTextBox1.AppendText("This is the string I search for\n"); richTextBox1.AppendText("Another Hello World Again\n"); } private void button1_Click(object sender, System.EventArgs e) { int loc = richTextBox1.Find("string"); int linePos= richTextBox1.GetLineFromCharIndex(loc); int lineLen = richTextBox1.Lines[linePos].Length; int lineStart = richTextBox1.Lines[linePos].IndexOf("string"); richTextBox1.Select(lineStart,lineLen); richTextBox1.SelectionColor = Color.Blue; richTextBox1.SelectedText = richTextBox1.Lines[linePos]; richTextBox1.AppendText("strPos: " + loc + ", Len: " + lineLen + ", linestart: " + lineStart); }

    C# question help

  • Highlight a line that contains a string
    C clatten

    OK, I tried that and it worked somehow but there's still a problem. Given the code below I search for the string "string" and then select the line that contains the string "This is the string I search for". The result will be that string is replaced and highlighted and thus giving: "This is the This is the string I search for I search for". I have tried several solutions avoiding this, but I assume I need to use SelectedText.Replace or set Select to start from the beginning of the line But I can't find out a way to calculate where the line starts and ends. Anyone that can hint how to proceed? private void WinForm_Load(object sender, System.EventArgs e) { richTextBox1.Text = "Hello world\n"; richTextBox1.AppendText("This is the string I search for\n"); richTextBox1.AppendText("The last row\n"); } } private void button1_Click(object sender, System.EventArgs e) { int locate = richTextBox1.Find("string"); int line = richTextBox1.GetLineFromCharIndex(locate); richTextBox1.SelectionColor = Color.Red; richTextBox1.SelectedText = richTextBox1.Lines[line]; string q = richTextBox1.Lines[line];; richTextBox1.SelectionProtected = true; int len = richTextBox1.Lines[line].Length; string txt = richTextBox1.Lines[line]; richTextBox1.SelectionCharOffset = 5; richTextBox1.AppendText("Line no: " + line + ", Locate: " + locate + ", Len: " + len + "\n"); richTextBox1.AppendText(txt + "\n"); richTextBox1.AppendText("q: " + q); }

    C# question help

  • Highlight a line that contains a string
    C clatten

    Since I received good answers on my previous question I'll go for a new. I have a richtextbox and like to highlight lines that contain a specific string. I'v found the .Find method which lets me search for a string and then with the selection methods I can highlight by changing font and foreground colour etc. But the problem is that only the search string becomes selected and not the whole line. Also only the first occurrence is selected but I guess that's solvable. Is there some way to achieve this with .Find or is there any other way I can/should go?

    C# question help

  • Problems with richtextbox
    C clatten

    Using stringbuilder did the trick. Thanx a lot.

    C# help announcement

  • Problems with richtextbox
    C clatten

    Looking into it more it's seems to me that it works as intened but as soon as the loop where the text is appended to the richtextbox exceeds 2-3000 it will take several minutes. Is there any better way to add text to the control than AppendText? I'd like to stick with richtextbox since I'm thinking of highlighting some lines.

    C# help announcement

  • Problems with richtextbox
    C clatten

    I have a problem with the richtextbox. I'd like to read a logfile, then reverse it. This did not seem to be possible with LoadFile so I read the file into an arraylist and outputs it to the richtextbox with AppendText. With this solution it will also be quite easy to add output filters. The problem is that there seems to be problems with number of lines the richtextbox can hold. If I output 2000 lines it takes approx. 5s before it's done, 10000 lines I waited about 1 minute and it was still not finished. The logfiles will contain much more than 10000 lines so this is a big problem. Using LoadFile it takes no time at all. So something's very wrong with my solution, anyone that can hint to me what's wrong, and maybe suggest a better approach to this. Since all files starts with the date I added a check that they e´start with 2004 otherwise I had >18000 lines in a logfile with 15000 lines. This seems to be me as one possible problem is that the logfile contains some "forbidden" characters that richtextbox cannot handle. Still LoadFile loads the file without problems. private void button1_Click(object sender, System.EventArgs e) { StreamReader sr = new StreamReader("c:\\logfile.txt"); //StreamReader sr = File.OpenText("c:\\logfile.txt"); string input = null; //Should read from the bottom, doesn't seem to work with LoadFile... //richTextBox1.LoadFile("c:\\logfile.txt",RichTextBoxStreamType.PlainText); ArrayList myList = new ArrayList(); int linecnt = 0; while ((input = sr.ReadLine()) != null) { if ( input.StartsWith("2")) { myList.Add(input); //linecnt++; } } sr.Close(); myList.TrimToSize(); myList.Reverse(); richTextBox1.Clear(); richTextBox1.Enabled = false; int q = myList.Count; //richTextBox1.Text = myList.Count.ToString() + "\t" + linecnt.ToString() + "\n"; for (int i=0;i < myList.Count ;i++) { richTextBox1.AppendText(myList[i].ToString() + "\n"); } richTextBox1.Update(); richTextBox1.Enabled = true; }

    C# help announcement
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups