|
Hi,
I have a dialog box implemented in C# and I want to make it the child of the currently active window. For this I want to get the ref to the current windows. I couldn't find anyway so that I could get this ref as Windows.Form object.
One thing I tried was that I used user32.dll GetForegroundWindow() to get the handle to the currently active windows and then use NativeWindow.FromHandle(IntPtr ) method to get the current windows as NativeWindow ref. But in this case I get the handler to the current windiows but the FromHandle method return me always null.
Does anyone know of a way to get the currently active windows?
Thanks
Bilal
Bilal Farooq
|
|
|
|
|
Form.ActiveForm or Form.ActiveMdiChild static methods.
But use myDialogWindow.ShowDialog(this) method I think.
Hi,
AW
|
|
|
|
|
AW,
What I want is a bit different. My application runs in its own memory space and I want to associate it to an application with some differnt memory space. For instance, I have an open word document and I want to associate that word document to my dialog as parent.
Thanks
Bilal
Bilal Farooq
|
|
|
|
|
You can't parent a dialog in one process to another in another process. This isn't possible. The most you can do is position it by getting the currently active window, getting it's position information, and then update your window's position (which should have Form.TopLevel set to true ) so that it appears to be parented.
To get the foreground window, P/Invoke GetForegroundWindow (not GetActiveWindow , which gets the active window attached to the calling thread). You can then P/Invoke GetWindowRect using the IntPtr (representing the HWND ) returned from GetForegroundWindow to get the coordinates of the foreground window and site your window accordingly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello
I am developing a syntax editor .
I need to give auto indentation feature to my editor .
I use C#.And i use richtextbox.
In the key press event ..
I try the following ..
private void richTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
// open and close braces indexes
int indexOfOpen;
int indexOfClose;
int lineno;
if (e.KeyValue == 221) // checking for "}" key
{
System.Diagnostics.Trace.WriteLine(this.richTextBox1.GetLineFromCharIndex(this.richTextBox1.SelectionStart).ToString());
// getting line number
lineno = this.richTextBox1.GetLineFromCharIndex(this.richTextBox1.SelectionStart);
while(lineno>0)
{
/*take the previous line from the position of "}" backwards and if it finds "{" charecter .get the
position of "{" charecter and adjust the position of
"}" charecter to the "{" charecter position.
*/
string[] test = this.richTextBox1.Lines;
string previousline = test[lineno-1];
if( previousline.StartsWith("{") )
{
indexOfOpen = previousline.IndexOf("{");
Point pos1 = this.richTextBox1.GetPositionFromCharIndex(indexofopen);
string currentline = test[lineno];
indexOfClose = currentline.IndexOf("}");
Point pos2 = this.richTextBox1.GetPositionFromCharIndex(indexOfClose);
pos2.X = pos1.X;
}
lineno--;
}
}
// check for the enter key
else if(e.KeyValue == 13)
{
string[] contents = richTextBox1.Lines;
int ilen = contents.Length;
string str = contents[ilen-1];
// setting indentation
richTextBox1.SelectionIndent = richTextBox1.SelectionStart;
}
Its somewhere mistake.I am new to C#.
Please can u correct me or give me sample code snippets?
I will be greatly helpful to me.
..
"They can because they think they can" - Voltaire
|
|
|
|
|
kumaru_san wrote:
And i use richtextbox.
Thats not gonna help much as you will realise it is rather limited. Here's what I use:
int GetIndent(string text, int tabsize)
{
if (text == null) return 0;
const char SPACE = ' ' ;
const char TAB = '\t';
int indent = 0, pos = 0, count = 0;
while (pos < text.Length)
{
switch(text[pos++])
{
case SPACE:
count++;
if (count == tabsize)
{
indent++;
count = 0;
}
break;
case TAB:
indent++;
count = 0;
break;
default:
return indent;
}
}
return indent;
}
|
|
|
|
|
dear leppie
thanks for the code snippet.
but i dont understand the logic which u try to explain me through ur code snippet.
Could u comment the source code and send it to me?
Do u think RichTextBox is not good for Line numbering ,auto indentation ,
ruler bar (on top of the text control similar to MS-Word)?
I downloaded xacc AdvancedTextBox also and its so nice ..but takes lot time
to understand the full source code.
Please help me.
"They can because they think they can" - Voltaire
|
|
|
|
|
I am sure there is a simple way to do this, but heck if I can figure it out tonight. Does anyone know of a way to float a child Form (say tool window) in an application properly?
I have a main Form, and I create a new child Form (tool window) with a parent of null and TopMost set to true. This allows my tool window to float over the app nicely. The problem is when I switch to another application, my toolwindow is still staring me in the face since it is TopMost!
How can I make it float topmost only when the application is active? Is there a way to distinguish between the application losing activation because the user switched to another app or because they clicked on the child tool window (which causes a deactivate)?
Any ideas would be greatly appreciated!
Michael
Developer, Author, Chef
|
|
|
|
|
Reset TopMost back to false and set the Owner property of your floating window to the main application form. See the Form.Owner property documentation in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Bah! I knew I was overlooking something simple, but was too brain-fried last night to come up with it. Many thanks again for input Heath!
Michael
Developer, Author, Chef
|
|
|
|
|
hello
I have got a nice doubt to ASK
I have created a user control in C#.net.
and that control is also implementing few interfaces.
but the problem is that ,when i integrate this
control on to a windows form, we can see the user
control for sometime, or days but after few days or
so we can't see it at design time.But is there in the form
at run time. We are using visualstudio 6.0 sourcesafe and
and during integration process most form has got
more than 10 controls. I have mailed it to few discussion
forums but didnt got a satisfying reply.
bye
jithesh
|
|
|
|
|
I wish to know, if there is any way to send an image from one form to another using a socket conection. Say like one form can send an image to another form on a remote computer that recieves it and views it. Can it be done just using sockets? Thanks in advanced 
|
|
|
|
|
One of the overloads for the Image.Save() method takes a System.IO.Stream. You could stream it memory, then send those bits via socket. Something like...
using System.IO;
using System.Net.Sockets;
Bitmap bmp = new Bitmap(@"c:\mypic.gif");
System.IO.MemoryStream memImage = new MemoryStream();
bmp.Save(memImage,System.Drawing.Imaging.ImageFormat.Gif);
byte[] data = memImage.ToArray();
Socket socket = new Socket(...your options here...);
socket.Send(data,0,data.Length,SocketFlags.None);
Hope that gets you started!
Michael
Developer, Author, Chef
|
|
|
|
|
Michael's suggestion is correct but you will also have to make sure that the client and server both send/receive the entire image. This means either putting a delimiter at the end of the image data or sending a 4 byte 'image data size' value before the image data. This is a basic socket principle so you don't not send or not receive the entire application level message.
|
|
|
|
|
Does anyone know how to increase the line spacing of items in a checkedListBox control, thank you in advance for your comments.
Interlocked
|
|
|
|
|
Hello, i have this web browser application which uses the AxWebBrowser control. It works pretty well except that i doesn't support auto complete. e.g. when u double click on an empty textbox, it will display a list of previous entered values.
Does it need special coding to handle it or can it be just a simple turning on of certain option?
<font=arial>Weiye Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
|
Hi All,
For my .NET Windows application (C#), I build the installation setup from .NET framework (Setup & Deployment Project).
I am unable to find the property, which I can set to give user the choice for installation i.e. whether installation will take place for the logged in user or for everyone [Everyone /"Just me" thingy]
Any help is appreciated
Thanks
Ruchi
|
|
|
|
|
So u are in C# right ?
good shoot.
First you create a new project
File > New >project >Setup and deployment > Setup. Just mentione the name and location where you want to keep your setup file.
Second Stage > Right now you are in FileSystem Window. Am i right ?
Ok. Here you can see Application Folder ,user's Desktop, User's Programs Menu some thing like this.
third stage > Choose add project from File Menu and choose existing project. After this you have to mention for which project file that you need to create setup file. Choose you project directroy.Choose the file
yourprojectname.csproj.
Just wait a second. After this stage right click the application folder and choose the option Add > Project Output.
Choose all in ProjectListBox except DebugOut Put And Source File. Then choose Cofiguration Tab and select Active.
then click ok.
You will get some file in the second Splited window of FileSystem Window.
Here you can view the two part of FileSystem Window.One is FileSystem on Target Machine and the other window is Output files. Select the application folder and right click on the next window.You will get a popup window with an option add. Choose the Add and go for the File option.
Here you can choose all aditional resouces file that you are going to use in your project.eg. icon's, configuration file etc.
Choose the all required files holding ctl key and add it. Here you got some more file right. Ok.
Next thing is if you want to give short cut to your project, then right click on the file
Primary output from xxxx(Active) and choose create shot cut. Now u will get one more file and rename it to what ever you want.
Choose the property of that shortcut and choose the Icon and browse in application folder. In application forlder you will get your project icon.
And create the project(build). If your project is error free then your effort will always successfull.
enjoy coding.
hai, feel free to contact
Sreejith SS Nair
|
|
|
|
|
Thanks Sreejith for the reply.
Actually I could create the setup project, but problem I have is in specifying property such that at the time of installation it asks me, if the installation is to be done for "All Users" or "Logged in user"
Thanks
Ruchi
|
|
|
|
|
I don't know what in the hell the other guy is trying to tell you, but I've been developing installer packages since Windows Installer 1.0 beta.
The solution is simple: the ALLUSERS property is what you're looking for. You can both get and set this property.
The default Windows Installer project in VS.NET does include a dialog that sets this accordingly (see the Windows Installer SDK in MSDN[^] for more information). This in turn changes the meaning of pre-defined folder properties, like DesktopFolder . Depending on the user's access privileges and the setting of ALLUSERS , the DesktopFolder - for example - would point to either the user's desktop folder or the All Users' desktop folder.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath for the reply.
The solution you suggested works by specifying command line params like this
msiexec /I mysetup.msi ALLUSERS=2
But I couldn't find a way such that I set this property at the time I create MSI file from the .NET "Setup & Deployment" project.
I am sorry I am a little novice there. Please suggest.
Thanks
Ruchi
|
|
|
|
|
i need a solution for making an event (like click event..) on the scrollbar of the TreeView.
|
|
|
|
|
Extend the TreeView with your own class and override WndProc . Inside, you can handle the scroll bar notification messages that can fire whatever events you want, such as adding your own. For example, you could have a Scroll event and fill it's EventArgs derivative with scroll information, which you can also get from the WParam and LParam properties of the Message that's passed as a reference to your overridden WndProc (just don't forget to call base.WndProc ).
You can find more information about the scroll bar notification messages - which are sent to the parent control, i.e. the TreeView - in the Platform SDK documentation for Scroll Bars[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm building some Control that displays a form that let's me do some operations. (like the combobox, datetimepicker, etc.)
Now, I nees that the poped area will be on top of all windows like the regular ComboBox dropped region, and wouldn't be trimmed by the parent control rectangle.
What is the currect technique for this?
(Sorry about my terrible English, I'm not an american.)
|
|
|
|