|
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
|
|
|
|
|
this works if i just wanna draw a Bmp. what if I draw something else.
Shall I always preserve what i draw in a bmp and repaint the bmp when needed?
|
|
|
|
|
clarkwuzhe wrote:
what if I draw something else.
Shall I always preserve what i draw in a bmp and repaint the bmp when needed?
That depends on what you ultimately want to do. If there are only a small number of formats which your app might draw, then you could keep a variable around for each type, and yet another one that tells your Paint handler which one to render. That would be useful if you need to save (or otherwise preserve) that exact graphics format. However, that doesn't seem likely based on your original question.
Otherwise, it might be easier, as you mentioned, to convert each type to a Bitmap (which is probably the most universal and flexible type to use with GDI+), and always draw whatever's in mybmp . Behind the scenes, GDI+ will always convert an image to bitmap format (if necessary) for the actual rendering anyway.
Like I posted earlier, I do not know why you are bypassing PictureBox 's Image property, which will handle the Paint requests automatically. As it stands, you could use a Label (or most any other control) and draw using its Graphics object too. PictureBox already contains methods for fairly custom image drawing, which you do not need if you are custom drawing yourself. Just letting you know; I don't mean to confuse you.
Cheers
|
|
|
|
|
I have asked this question before...but never got to many posts. im wondering how i can get a good start in the software dev field (in C#) i am enrolled in a 6 month tech school (starting next month on the 9th) to get my MCSD...after which the school helps you find a job...what other things would you recommend for me to be doing in addition to getting my MCSD ?
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
Experience. No-one cares about whatever whiz-bang work you may have done at home. Or even at school to a large degree.
Try find some part-time work even vaguely related to the industry or even volunteer somewhere. Even it's just crappy work that has no value, it's something you can put on your CV and bullshit about in the interview. And it shows that you have initiative.
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
NEW: Awasu v0.7[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
yeah...i'm currently looking to develop...anything with someone.....do you (or anyone) have anything you are looking for help with...however meaningless...the job is... im the man for it..lol
Jesse M
The Code Project Is Your Friend...
|
|
|
|