|
Hi,
I'm trying to have to windows inside another ( tree view in the left side , and my own form in the right side), I've tried this code ( only to add my own window there... )
Form1 MainForm = new Form1();
HijaDrcha RightWindow = new HijaDrcha();
MainForm.Controls.Add(RightWindow);
Application.Run(MainForm);
This compiles fine, but when I try to run this, it gives me one exception , any clues about how can this work ? ( or did I miss some parameter in the form or ... ?).
Thanks in advance,
Braulio
|
|
|
|
|
Whats the exception? You might try using a splitter window as well.
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|
|
Hi,
If I use an Splitter, the exception that I get is:
"Cannot Add a top level control to a control"
Is there some style that I can switch off ? ( how ?), or Window Forms are top level controls ?
Thanks in advance, greetings
Braulio
|
|
|
|
|
I don't think you can add a form to another form unless it's an MDI container (and I don't think that's what you're trying to do). The "inner" form should probably be a control rather than a form.
Paul
And you run and you run to catch up with the sun, but it's sinking Racing around to come up behind you again The sun is the same in a relative way, but you're older Shorter of breath, one day closer to death - Pink Floyd, Time
|
|
|
|
|
Can I model a control as a form ? In MFC it worked like, "I have two views ( edit the aspect with the resource editor), then use CSplitterWnd and add both views).
Sorry, but I'm new to this Windows Forms World...
Thanks
Braulio
|
|
|
|
|
Braulio Díez wrote:
Can I model a control as a form ?
Yeah, sort of. You can create a custom control and drop a number of other controls into it, then treat it just like a window. Then you can dock it into your main window. (dock one control to the left, then dock a splitter to the left, then dock another control to full; that creates a split window as you are looking for)
A window, in effect, is considered to be a top-level control. It contains a Controls collection, as does any other kind of control.
Paul
And you run and you run to catch up with the sun, but it's sinking Racing around to come up behind you again The sun is the same in a relative way, but you're older Shorter of breath, one day closer to death - Pink Floyd, Time
|
|
|
|
|
Hi,
If I use one Splitter, the error message that I get is:
"Cannot Add a top level control to a control"
Thanks
Braulio
|
|
|
|
|
yes this is true. since both are windows. make the innter one as either panel or any other control rather than windows form.
then i think u r all set

|
|
|
|
|
On the form you are adding (RightWindow) set the TopLevel property to false..you may also want to change the FormBorderStyle to something more appropriate.
HTH,
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
How can i get the handle of an application like Internet Explorer? Is there a function like FindWindow() in c++?
thanks
|
|
|
|
|
Not sure, but can't you just use Interop and call the WinApi FindWindow() function ?
R.Bischoff | C++
.NET, Kommst du mit?
|
|
|
|
|
<br />
Process[] processes = Process.GetProcesses();<br />
for(int x=0;x < processes.Length-1;x++)<br />
{<br />
try<br />
{<br />
string name = processes[x].MainModule.FileName; <br />
if(name.EndsWith("iexplore.exe"))<br />
{<br />
Process instance = processes[x];<br />
instance.Handle
}<br />
catch(System.NullReferenceException e)<br />
{<br />
}<br />
}<br />
|
|
|
|
|
C#
Is it possible to declare const array of strings?
Or is there some other way to enumerate or group const strings?
(i.e.)
const string[] strData = { FIRST="John", LAST="Mark" };
so I can acces it by (like enumeration):
strData[FIRST];
|
|
|
|
|
You can try this way:
private struct myStruct{
public static string FIRST = "John";
public static string LAST = "Mark";
}
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(myStruct.FIRST);
Console.WriteLine(myStruct.LAST);
Console.ReadLine();
}
Cheers,
Simon
"The day I swan around in expensive suits is the day I hope someone puts a bullet in my head.", Chris Carter.
animation mechanics in SVG
|
|
|
|
|
I've tried something like that before but didn't work because I've declared a variable of that type. But accesing the members directy seams to work fine. It also works with const instead of static .
Thank you Simon.
|
|
|
|
|
Hi ,
i have a usercontrol with some childcontrols on , one of the childcontrols have focus (can be any of the child controls)
the problem is that when i click a control outside the usercontrol , the usercontrol does not get notified that it has lost focus , it is the currently active child control that gets the "wm_killfocus" ,, is there ANY way to make the containing usercontrol to get notified of such events in the childcontrols , w/o having to attatch a zillion of eventhandlers to them?
any idea's?
//Roger
|
|
|
|
|
...is there ANY way to make the containing usercontrol to get notified of such events in the childcontrols , w/o having to attatch a zillion of eventhandlers to them?
Not that I can think of off-hand. I am familiar with your situation, and have solved it by overriding event handlers. I do not think it would be all that bad, since you only have to deal with one event handler per child control.
If you are not already, the best way to intercept messages in a custom control is to override the existing protected event handler, rather than the usual registering of a handler. For example:
internal class MyChildCtrl : TextBox { //wrap a textbox for use as a child ctrl,
//and use just like the unwrapped version.
//...
protected override void OnLostFocus(EventArgs e) {
Debug.WriteLine("LostFocus in "+this.Name);
this.Parent.ChildCtrlLostFocus(this, e); //call a method you put in the parent ctrl,
//which in turn can raise the parent's
//LostFocus event if you like.
base.OnLostFocus(e); //always call the base class' event handler
}
}
Overriden handlers are much more efficient than registered handlers created in the Form Designer, partly because they are direct and do not have to be mapped. I know it's annoying to write handlers, but one such as this can be pasted into every wrapped child ctrl in your UserControl (they're all the same). On the plus side, you do not have to += an event handler for each ctrl, since you're overriding directly.
Sorry I couldn't provide a simpler solution, but Windows only notifies the particular ctrl that loses focus, and the one that gains it, not any of the parents. I do not think .Net provides a standard way of bubbling a focus event up to a parent.
Cheers
|
|
|
|
|
Does anyone know of a "clean" way to detect if a user is online? Code examples are appreciated.
|
|
|
|
|
P/Invoke BOOL InternetGetConnectedState(LPDWORD lpdwFlags, DWORD dwReserved)
|
|
|
|
|

<br />
using System.Runtime.InteropServices;<br />
<br />
...<br />
<br />
public class InternetConnection<br />
{<br />
[DllImport("wininet.dll")]<br />
public static extern bool InternetGetConnectedStateEx(out int lpdwFlags, byte[] szConn, int iConnSize, int dwReserved);<br />
<br />
public enum Status: int<br />
{<br />
INTERNET_CONNECTION_MODEM = 1,<br />
INTERNET_CONNECTION_LAN = 2,<br />
INTERNET_CONNECTION_PROXY = 4,<br />
INTERNET_RAS_INSTALLED = 16,<br />
INTERNET_CONNECTION_OFFLINE = 32,<br />
INTERNET_CONNECTION_CONFIGURED = 64<br />
}<br />
<br />
public static bool Connected<br />
{<br />
get {<br />
bool bConn = false;<br />
int flags = 0;<br />
byte [] cName = new byte[512];<br />
if(InternetGetConnectedStateEx(out flags, cName, 512, 0)) <br />
{<br />
bConn = true;<br />
}<br />
return bConn;<br />
}<br />
}<br />
<br />
public InternetConnection()<br />
{<br />
}<br />
}<br />
<br />
...<br />
<br />
InternetConnection inet = new InternetConnection();<br />
if(inet.Connected)<br />
{<br />
...<br />
}<br />
else<br />
{<br />
}<br />
Cheers,
John
|
|
|
|
|
I am new to C# and I thank everyone who helped me on my silly questions.
and here is one more:
the following code is going to draw a selected image in a picturebox control,
however, since I use graphics.drawimage, the picture will not be redrawn if covered by something else.
may someone please help me?
private void menuItem2_Click(object sender, System.EventArgs e)
{
Point myloc=new Point(0,0);
Size mysize=new Size(640,480);
Rectangle position =new Rectangle(myloc,mysize);
ofd.Filter="Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
if (ofd.ShowDialog()==DialogResult.OK)
{
fileio.filetxt=ofd.FileName;
Bitmap mybmp=new Bitmap(fileio.filetxt);
Graphics g=pictureBox_cur.CreateGraphics();
g.DrawImage(mybmp,position);
}
}
thanks everybody
|
|
|
|
|
use
g.Dispose()
at the end when using resources like images with graphics object.
PAresh;)
|
|
|
|
|
Since you are only painting/drawing the image once, the PictureBox will redraw over it with whatever contents it knows about, if any. That is, the PictureBox has no way to know that you painted a specific image in its client area, so it cannot redraw it when the system tells it to repaint its contents.
I assume you have a specific reason not to just set the PictureBox 's Image property, and instead need to custom draw. Perhaps the easiest way would be to handle the control's Paint event, as you did with menuItem2's Click event. VS.Net will create a function like:
private void pictureBox_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(mybmp, position);
}
You will need to store mybmp and position somewhere the Paint handler can see it, and keep the code in your menuItem2_Click handler that sets the Bitmap and Rectangle. Since the Graphics object is already supplied by the PaintEventArgs object here, do not destroy it.
Windows will fire your Paint handler anytime the control needs to be redrawn.
Cheers
|
|
|
|
|
if I do:
private void pictureBox_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(mybmp, position); //put your drawing code here
}
the system will try to paint mybmp when the form is loaded and create an error
System.NullreferenceException
|
|
|
|
|
I anticipated that problem, but left that out since my post was already getting long. You will need to put error handling in the code such as:
private void pictureBox_Paint(object sender, PaintEventArgs e)
{
if (mybmp != null)
{
e.Graphics.DrawImage(mybmp, position);
}
}
and where the variables are declared, such as in your form's code:
private Bitmap mybmp=null;
private Rectangle position;
That should take care of the errors you got. This way, only when you have loaded a bitmap, will one be drawn.
Cheers
|
|
|
|
|