|
Oh... I made a mistake. Change the foreach line:
<br />
foreach (Control control in form1.Controls)<br />
The Controls property gives you a collection class over which you can iterate. You can do the same thing with any container control.
|
|
|
|
|
I was just wondering if someone could nudge me in the right direction on this one. I am just trying to figure out how i can grab formatting information on individual characters in a richtextbox.
Example:
if i had this in the rich text box:
"Mary had a little lamb"
I would want to be anble to know that M is bold, as are a r and y, and so on. Any ideas?
Yes, I am the highly suggestable type.
|
|
|
|
|
Look into the the RTF property of the RichTextBox. There you will find the text including all formatting. If I remember correct bolded text is enclosed with '\b' and '\b0' or something similar. You will have to search for the specifications (Google is your friend ) or just try it out.
|
|
|
|
|
Robert Rohde wrote:
You will have to search for the specifications (Google is your friend ) or just try it out.
Actually, MSN Search[^] should be your friend now, but I'm not biased or anything.
Rather than digging through RTF[^] using the RichTextBox.Rtf property content, you can obtain this information for a character range. IT really depends on what you need to do, though. Using a selection requires that you move the cursor around, which may or may not fulfill your requirements. If you want to get the formatting for the current selection, however, this is by far the easiest way (since those certainly no easy way to associate the current selection with a character range in the Rtf property).
If you read the member documentation[^] for the RichTextBox class, you'll notice a lot of public properties with "selection" or "selected" in them, like SelectionFont and SelectionColor . From this information you can easily obtain the formatting for the current selection. If you need to change the current selection to a different character range, adjust the SelectionStart and SelectionLength properties.
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]
|
|
|
|
|
I actually came up with a nice little tool in the meantime. What i was trying to do was convert richtext into html. i have this code tied to a button, and when i click it, it changes the richtext into html, even going so far as to provide proper tag nesting:
<code> int y = 0;
b = "0";
i = "0";
u = "0";
foreach(char t in this.thrower.Text)
{
this.thrower.Select(y,1);
string h = this.thrower.SelectedText;
switch(this.thrower.SelectionFont.Bold)
{
case true:
if(b == "0")
{
b = "1";
}
break;
case false:
if(b == "2")
{
b = "3";
}
break;
}
if(b == "1")
{
h = "<strong>" + h;
b = "2";
}
else if(b == "3")
{
h = "</strong>" + h;
b = "0";
}
switch(this.thrower.SelectionFont.Italic)
{
case true:
if(i == "0")
{
i = "1";
}
break;
case false:
if(i == "2")
{
i = "3";
}
break;
}
if(i == "1")
{
h = "<i>" + h;
i = "2";
}
else if(i == "3")
{
h = "</i>" + h;
i = "0";
}
switch(this.thrower.SelectionFont.Underline)
{
case true:
if(u == "0")
{
u = "1";
}
break;
case false:
if(u == "2")
{
u = "3";
}
break;
}
if(u == "1")
{
h = "<u>" + h;
u = "2";
}
else if(u == "3")
{
h = "</u>" + h;
u = "0";
}
if(this.thrower.SelectedText == "\n")
{
h = "<br>\r\n";
}
this.catcher.Text = this.catcher.Text + h;
y++;
}</code>
I'm pretty happy with the results.
The only thing i am running into now is that i have made nice little bold, italic and underline buttons, but, i seem to only be able to set one property at a time.
for instance, if i set this.thrower.SelectedFont to Bold, it is bold, but if it was just underlined (and i didnt turn it off), it shows up as bold with no underline. is there any way to set multiple types?
Yes, I am the highly suggestable type.
|
|
|
|
|
Wow, that is the most grotesque use of switch I've ever seen. Use a simple if statement to make your code more readable. Someone sustaining code like that I'm sure would hold a grudge.
if (thrower.SelectionFont.Bold)
{
b == 1;
}
else
{
b = 2;
} How you set these variables depends greatly on your algorithm. Every time you change the selection you must reset your variables, like b , i , and u . As you're writing your text check the value of each one to determine if you need to write them. Writing HTML like the following is completely valid:
<b><u>bold and underlined text</u></b> You might consider - depending on your requirements - one of many RTF to HTML converters, which you can search[^] for, or click "Search comments" directly above this forum to see the many discussions we've had about this before.
The method you're using now is pretty restrictive and won't handy much of what RTF can do. If your RTF documents are expected to be simple, however, your approach may be fine. Many of the RTF to HTML converters are, however, pretty inexpensive.
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]
|
|
|
|
|
BTW, you can use the <pre></pre> tags to format multi-line text correctly. It's much easier to read. This site will also automatically send notification of replies if you reply to someone else. Had I not notice your reply to yourself I never would've known you had another question. Please be sure to directly replies appropriate to take advantage of the forum in the best possible way.
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 have the following code
**********
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = "notepad.exe";
processInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process process = Process.Start(processInfo);
**********
once the process is running, how could I programmatically change the window status to normal or maximized?
The thing is that I need to do some stuff before displaying the process window, so after I'm done then I need to display it
Thanks in advance
Isaac B
|
|
|
|
|
AFAIK, there is no method in the .NET Framework you can use to restore the window. It looks like you'll have to P/Invoke a call to the Win32 API function <a href="http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/showwindow.asp?frame=true" rel="nofollow">ShowWindow</a>[<a href="http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/showwindow.asp?frame=true" target="_blank" rel="nofollow" title="New Window">^</a>] . All you need to supply in the handle to the window that was created. You can get that from the MainWindowHandle property of the Process object that was created when you called Process.Start() .
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
The ShowWindow function can minimize, maximize, or restore a window. It can also set the window's visibility and activation states.
MSDN link for ShowWindow[^]
Take a look at www.pinvoke.net[^] the pinvoke wiki
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
I tried using the ShowWindow but it just won't work, what I'm trying to do is put an application like notepad or paint or anything else inside windows forms
private void btnStart_Click(object sender, System.EventArgs e)
{
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = "notepad.exe";
processInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process process = Process.Start(processInfo);
Process[] procs = Process.GetProcessesByName("notepad");
if (procs.Length != 0)
{
IntPtr hwnd = procs[0].MainWindowHandle;
CloseWindow(hwnd);
SetParent(hwnd, pbDisplay.Handle);
ShowWindow(hwnd, 5);
}
else
{
MessageBox.Show("Notepad is not running");
}
}
It seems there is some issue with the process focus or something like that, haven't found much info. about the topic, anyone has any idea?
|
|
|
|
|
What do you mean by "inside windows forms"?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I mean that I have a form in winforms that has a picture box in the code below called pbDisplay, I get the handler of the picture box and with SetParent() I put the notepad inside the picture box
I start notepad hidden so the user doesnt see when the notepad opens outside the application, but the problem is now that the notepad is inside how do i change the status from hidden to normal or maximized
In fact the application I want to put inside the picture box is called IPass, but I'm hoping that after being able to do it with notepad the change wont be that much problem
**************************
private void btnStart_Click(object sender, System.EventArgs e)
{
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = "notepad.exe";
processInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process process = Process.Start(processInfo);
Process[] procs = Process.GetProcessesByName("notepad");
if (procs.Length != 0)
{
IntPtr hwnd = procs[0].MainWindowHandle;
CloseWindow(hwnd);
SetParent(hwnd, pbDisplay.Handle);
ShowWindow(hwnd, 5);
}
else
{
MessageBox.Show("Notepad is not running");
}
}
|
|
|
|
|
Well, what your doing is definitly non-standard. There is no documentation describing what your doing and what the side-effects are. ShowWindow works perfectly in all other instances.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Has anyone ever tried to code a piece of software to browse his bank(hsbc for instance) accounts, buy sell stock shares thru this software. This software is not meant to be only with ASP.NET, it can also be built using MFC or any other related libraries of .NET framework or previous Microsoft related libraries. I have got a similar piece of code in Java, however I would like to study its .NET version, what would it be like and what libraries of framework would be used, what methods be called to make a connection to the bank's server, browse accounts and buy and sell stock shares. I am trying to code a non-asp version of it for http://www.hsbc.com.tr/. Does anyone have any idea. I would later automatize my buying and selling thru some technical indicators..
Thank you for any opinions..
|
|
|
|
|
Please don't cross-post in multiple forums.
Charlie
if(!curlies){ return; }
|
|
|
|
|
I was trying to implement:
Form_MouseEnter(object sender, System.EventArgs e)
{
if(!this.Focused)
this.Focus();
}
I have child controls that fill the entire form... so MouseEnter event never gets fired. I figured that MouseEnter would fire as soon as the mouse touched the form border, but that is not the case as it only gets fired when inside the border (and if you have child controls that fill the form background, then it will never get fired). It would be nice to have all child controls automatically inherit the parent's event handlers (without writting a function call: ChildControl_MouseEnter { Form_MouseEnter } for every child control).
It appears that every child control overrides the parent's event handlers (at least out-of-the-box microsoft controls... not neccessarily true for custom controls).
Is there an easy way to have child controls automatically call their parent event handlers without implementing the child's mouseEnter event?
Better yet, is there a way that you can have event handlers fire based on the Windows Form Border (which seems to be tied into the O.S, such as when you click the title bar of a form... the control gets focus)?
|
|
|
|
|
You could do this by manually setting the Region of the control. Search google for "non-rectangular forms" or similar for some examples of setting the region.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
How would that solve the problem of firing events for the window frame? Sure you could draw only the client area then draw the borders yourself, but 1) what a pain in the arse, and 2) you could achieve that by simply setting Form.FormBorderStyle to FormBorderStyle.None .
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]
|
|
|
|
|
To be honest, I didn't read through his entire post, I saw it about to fall off the board's main page without replies, so I posted. I guess my thinking was that by setting the region of the form, you could have events be raised even if you were outside the client area.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
Events are only fired for the client area. Setting the region to a small value changing the client area (and can mask the window frame). You can't really increase it, though. A window must be confined to the RECT defined for its window class.
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]
|
|
|
|
|
Heath Stewart wrote:
You can't really increase it, though. A window must be confined to the RECT defined for its window class.
Interesting, I'll have to try that out and see for myself.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
Events are only fired for the client area and not the window frame. To receive messages for the window frame, you need to handle the appropriate WM_NC* window message by overriding WndProc .
Search for WM_NCMOUSEMOVE[^] in this forum for examples about how to implement this.
You should also read Consuming Unmanaged DLL Functions[^] and about the Windows Controls[^] - the Common Controls which most Windows Forms controls encapsulate to provide a consistent user interface.
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 tips and pointing me in the right direction... I now know what to search for and try.
Thanks!!!
|
|
|
|