|
Thx for info...Looks like porting my program is gonna be a learning experience.
|
|
|
|
|
|
Hi all,
How to communicate between an application and a windows service on the same machine.
Here I want to access data generated by service and process it through an application(UI) and then, send some data from the application to the service to add it in the log.
Thanks..
|
|
|
|
|
The best way is whatever inter-process communication (IPC) protocol works best for you. If both executables are managed, then I recommend .NET Remoting[^]. The remoting infrastructure loosly defines the transport and formatting layers for IPC and is built on and for managed code. It isn't a straight-forward infrastructure, however, so I do recommend picking up a book on it depending on what you need to do (the move advanced objects you require to communicate, the more you should invest a an inexpensive book).
You could also P/Invoke RPC functions, but to do so would require you building an infrastructure similar to .NET Remoting.
With .NET Remoting you should use a TcpChannel in this case (lower overhead; .NET 2.0 will introduce named pipes for a channel for faster transport) but you could always use a TcpClient and TcpListener with your own protocol for marshaling (serializing and transporting) objects.
The sky is the limit on this one.
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 have created several layers of dialog boxes using MFC C++ .Net. However, I do not want to automatically go back to calling dialog when I hit return anywhere in the active dialog. I want to just be able to click on OK button to do this.
I have the OK button as not the Default button, but clicking anywhere in Dialog box always closes the active Dialog Box and goes back to calling Dialog box. Is there a fix?
|
|
|
|
|
This forum is for C# questions. Ask again in the Managed C++ 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]
|
|
|
|
|
Will very much appreciate if someone pointed me to a Wintab32 library class in c sharp
|
|
|
|
|
|
In VB6, you can do the following:
foreach control in form
//do stuff to each
next
In c#, you have to add an identifier to use the foreach with the array or collection.
I want to loop through a group of controls (like radiobuttons, etc.)
i.e. foreach (RadioButton in form1) {//do code}
Obviously, this code will not work, but does anyone know how this can be done in C# ? I would appreciate the help.
Thanks in advance.
|
|
|
|
|
Just declare a variable for RadioButton inside foreach like this
foreach(RadioButton radioButton in form1) {//do code}
|
|
|
|
|
This will only work if there are only RadioButtons on the form.
I would try the following:
foreach (Control control in form1) {
RadioButton rb = control as RadioButton;
if (rb != null) {
}
}
|
|
|
|
|
That option will work (going through each control, then doing an if-statement. Another option would be to write your own iterator that returns an IEnumerable list of radio buttons.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
OK... I admit to being a newbi (one that WANTS to learn), but something is not working.
I cannot use the foreach because of the following:
" foreach statement cannot operate on variables of type 'System.Windows.Forms.GroupBox' because 'System.Windows.Forms.GroupBox' does not contain a definition for 'GetEnumerator', or it is inaccessible
I tried it in a usercontrol as well with the same error.
Do I need to make the groupbox IEnumerable? I am not sure about "write your own iterator that returns an IEnumerable list of radio buttons". Sounds like fun... Could you let me know what is involved?
THanks
|
|
|
|
|
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?
|
|
|
|