|
10x man !! But I already found the answer.
Some sites to look for:
http://abstractvb.com/code.asp?P=1&F=51 [VB site]
Google.com [try to search for every interface name you found or question about - it's really helps]
"I have not failed.
I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
|
|
|
|
|
This is probably a basic question to one who has the answer, but I can't seem to find the forest for the trees.
I put together the main form (frmMain) and I have several user controls that I put together. Silly me, I only tested the process on a single form before moving forward.
I created the main form with a panel (pnlMain) into which I paste my user control (UC). When the user clicks on a button, my intention was to call a public routine in frmMain that would 1) Hide the current UC and then load and paste an appropriate new UC into the panel.
The problem is hierarchy. No matter how I put the controls together, once the child form is open, I can't get back to the main form to tell it to do something different. I've tried a few different variations but I keep running into the hierarchy issue no matter the method of object creation.
I've done this type of thing in Delphi but can't seem to figure out the C# secret.
Thanks for the help.
DBetting
|
|
|
|
|
I not sure I understand your issue. Seems to me there should be many ways to get back to your main from.
Anyway, try this;
Form frmMainRef = (frmMain)this.Parent();
//frmMainRef is a reference to the parent. If you are nested deaply you may need to put this into a loop until ype of frmMainRef is form.
Something like this...
Form frmMainRef = (frmMain)this.Parent();
while(frmMainRef != null && frmMainRef.GetType() == typeof(Form)
{
frmMainRef = (frmMain)this.Parent();
}
good luck, let me know
|
|
|
|
|
For a simple test of visibility and the concept: Given a main form (frmMain) with a panel (pnlMain), using the following:
public class frmMain : System.Windows.Forms.Form<br />
{<br />
...<br />
public ucForm1 UCForm1 = new ucForm1();<br />
public ucForm2 UCForm2 = new ucForm2();<br />
... <br />
public frmMain()<br />
{<br />
InitializeComponent();<br />
UCForm1.Parent = this.pnlMain;<br />
UCForm1.Visible = true;<br />
}<br />
<br />
public void ShowUCForm2()<br />
{<br />
UCForm1.Visible = false;<br />
UCForm1.Parent = null;<br />
UCForm2.Parent = this.pnlMain;<br />
UCForm2.Visible = true;<br />
}<br />
}
then given a User Control with a single button (btnViewOtherForm) using the following:
public class ucForm1 : System.Windows.Forms.UserControl<br />
{<br />
...<br />
private void btnViewOtherForm_Click(object sender, System.EventArgs e)<br />
{ <br />
Form frmParent = (frmMain) this.Parent;<br />
frmParent.ShowUCForm1();<br />
}<br />
}
ucForm2 can be blank. I tried the suggestion, but the reference to ShowUCForm2 cannot be found. I cannot use the loop because the compiler wants to find the reference before it allows it to be used. I've tried several flavors of trying to access the parent, but obviously not the correct one yet.
In this case, the parent should be two levels up. ucForm1.Parent should be pnlMain whose parent should be frmMain.
Thanks
Dan
|
|
|
|
|
I am traveling today. If you wanted to send me the example project, I would work on it during my layover.
|
|
|
|
|
Is there a ClientToScreen() equivalent in c#?
Paul
|
|
|
|
|
|
Thanks,
It is amazing how something so obvious can be so elusive !!
|
|
|
|
|
|
I CAN YOU!
uh... email me.
/\ |_ E X E GG
|
|
|
|
|
Hi All,
I want to connect to Access Database. I am using Visual Studio.NET beta version. In that I want to use the class System.Data.ADO.ADODataSetCommand. But, when I use this in my code i am getting compile time error as
"the type or namespace name 'ADO' does not exists in the class or namespace 'System.Data' are you missing an Assembly reference.". In my 'References' 'System.Data' is present.
Can anybody tell me what specific assembly reference should I add to get 'ADO' namespace inside 'Data' namespace.
Thanks in advance.
regards,
Pranoti
|
|
|
|
|
I saw and used ADO in VB but most recently I was working with Access and C#. I used OleDb and it worked fine.
|
|
|
|
|
Hi,
Can you please tell me how can I use OleDB to connect with access.
Many Thanks,
Pranoti
|
|
|
|
|
In this area, I'm still very much an amateur. Your best bet would be to move your question to the SQL / ADO / ADO.Net section. You'll probably have half a dozen responses.
db
|
|
|
|
|
Hi all,
I am trying to use some custom resources. The following code works with images.
private void Form1_Load(object sender, System.EventArgs e)<br />
{ <br />
image1 = new Bitmap(GetType(),"icon1.png");<br />
image2 = new Bitmap(GetType(),"icon2.png");<br />
SelectionCursor = new Cursor(GetType(),"Cursor1.cur"); <br />
<br />
this.pictureBox1.BackgroundImage = image1; <br />
}
but when I try to change the current cursor as shown in the code below, I get the default IBeam.
private void AttachIcon(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
if (e.Button.Equals(MouseButtons.Left)) Cursor.Current = SelectionCursor;<br />
}
There are no compiler errors or warnings. The Cursor1.cur build action property is set to embedded resource. SelectionCursor is declared in the form as private Cursor SelectionCursor; Oh, and it works if I use a different system cursor in the event handler.
Does anyone have a sugestion?
Thanks, Paul
|
|
|
|
|
Got it!
The cursor was 32x32 and needed to be 16x16.
Paul
|
|
|
|
|
Be careful with code like this:
Paul Silvernail wrote:
private void Form1_Load(object sender, System.EventArgs e)
{
image1 = new Bitmap(GetType(),"icon1.png");
image2 = new Bitmap(GetType(),"icon2.png");
SelectionCursor = new Cursor(GetType(),"Cursor1.cur");
this.pictureBox1.BackgroundImage = image1;
}
If you create a new form which inherits from Form1 , but doesn't exist in the same namespace or assembly; the constructors will throw an exception because the resource can't be found. GetType() will return a Type object for the new form, not for Form1 resulting in the exception.
A better way to do it is to use typeof(Form1) so that you will always be referencing the correct Type object.
James
"then when you go to bed...wait, you dont do that do you....ok....when you plug into the 'hive mind' to charge yourself, ill hack into your head"
Nnamdi Onyeyiri over MSN
|
|
|
|
|
Hi,
I'm trying to add in an ImageList >3000 icons. It takes a lot of time. How can I do it work faster ? This ImageList will be used for viewing in Listview.
Thanks in advance
|
|
|
|
|
You wanna use a technic called using an imagestrip. The is some docs on MSDN how to do this, but basically you create a single really long image and load that into the imagelist. The rest is taken care off AFAIK.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Hi,
Sorry about putting this in the ASP.NET forum as well...
I've been developing an ASP.NET website for quite some time. The site is located on a w2k server and I have been using remote debugging, which was working quite fine. Took some time to get there though... but it worked just as it should.
Then suddenly, I cannot debug anymore ! I open VS (2003 btw.), open the project and press CTRL-F5 - the site opens in a browser and works fine. But if I press F5 instead, VS opens misc. debug windows (locals, call stack etc), writes "Run" in the caption - but no browser window shows up. Followingly, VS is locked up - it just doesn't respond. Then I can open a browser window manually and go to a page I know I have a breakpoint in, and VS will break at that point - however, still locked up. After that, all I can do is terminate the asp worker thread on the server and kill the VS process on the client. Very strange...
Anybody who has any ideas at all ? I've tried with different startup pages - but with the same result.
Thanks in advance.
Jan Hansen
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
|
|
|
|
|
|
I'm trying to develop a custom component library in C#. One of the set of objects in these components would be dropdown controls (DateTime picker with dropdown calender, Numeric edit with dropdown calculator, dropdown tree control, etc.)
From what I understand, for these objects (calendar, calculator, tree, etc.) to drop down in the "correct" way, they shouldn't be forms, but actually WS_POPUP windows that have the desktop as their parents. I'm imagining they should capture the mouse as soon as they drop down, report to their owner (textbox, or whatever dropped them down) and then release the mouse. Am I missing something? Is this the correct approach?
Problem number two. Is the following methodology right: I should define an interface (IPopupControl) and implement it with every desendant (like for instance: DropDownTreeView: TreeView, IPopupControl). The reason is then I should be able to assign any dropdown control to an owner, and then the owner would always call a method (like IPopupControl.Popup) because it will always be implemented. So in other words, the owner will always be accepting one object [object?] which is IPopupControl instead of a specific object (DropDownXXXX) according to what it wants to drop down. Then of course, every dropdown control will implement its own methods that are different, to report the data back to the owner control (most probably textbox).
I would have to call some Windows APIs in this process I would imagine. What are the disadvantages?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
profoundwhispers wrote:
From what I understand, for these objects (calendar, calculator, tree, etc.) to drop down in the "correct" way, they shouldn't be forms, but actually WS_POPUP windows that have the desktop as their parents. I'm imagining they should capture the mouse as soon as they drop down, report to their owner (textbox, or whatever dropped them down) and then release the mouse. Am I missing something? Is this the correct approach?
Forms are fine. You just have to set their style bits correctly.
WS_POPUP is out! You might think it should be used (as I once did), but when the WS_POPUP style is set, it causes the parent form's title bar to be "inactive" when the popup has focus. This would cause the user to be confused.
So here's the code to set the style bits:
int nStyle = GetWindowLong(this.Handle, GWL_STYLE); nStyle^=Win.User.WS_POPUP;
nStyle^=Win.User.WS_POPUPWINDOW;
SetWindowLong(Handle,GWL_STYLE,nStyle);
int nExStyle = GetWindowLong(this.Handle, GWL_EXSTYLE);
nExStyle|=WS_EX_PALETTEWINDOW;
SetWindowLong(Handle,GWL_EXSTYLE,nExStyle);
profoundwhispers wrote:
Problem number two. Is the following methodology right: I should define an interface (IPopupControl) and implement it with every desendant (like for instance: DropDownTreeView: TreeView, IPopupControl). The reason is then I should be able to assign any dropdown control to an owner, and then the owner would always call a method (like IPopupControl.Popup) because it will always be implemented. So in other words, the owner will always be accepting one object [object?] which is IPopupControl instead of a specific object (DropDownXXXX) according to what it wants to drop down. Then of course, every dropdown control will implement its own methods that are different, to report the data back to the owner control (most probably textbox).
That would be one way to do it, but then you would have to re-implement the basic popup code for each of them. Why not have a Popup class that they all derive from?
profoundwhispers wrote:
I would have to call some Windows APIs in this process I would imagine. What are the disadvantages?
Not any that I know of...
Ok, as far as closing the popup, here's how I do it:
With menus and combo dropdowns, you grab the mouse capture with SetCapture() when the mouse is outside your menu, and release the capture with ReleaseCapture() when the mouse is inside your menu (so that any contained controls can get mouse messages). Close the popup when a MouseUp event is recieved and the mouse coordinates are outside of the form's bounds. You will also want to close the popup when it recieves a WM_APPACTIVATE message where the app being activated is not your own.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
This is a quick fish for thoughts. I do know and am intending to do an article on how circular references to dll's can mess things up in when using csharp but for know I have this problem which is not a circular reference but may well get included in the article if anyone can come up with anything useful here
the problem is this.
I have a library dll say Libdll and a main project say mainexe and another dll that uses the library dll say libdll2.
When I compile the project the libdll2 project is compiled first and copies the libdll to the project output folder. Then when the mainexe compiles it complains that it can't copy the libdll to the output folder as this will overwrite the copy already there. ( even though it is the same library version ) This in effect means that the mainexe is unable to debug any code in the libdll.
Note that the main project is a test bed for building the libdll in the first place so the code is constantly changing and in need of debugging.
Any thoughts, answers?
pseudonym67
Neural Dot Net Articles 1-11 Start Here
Fuzzy Dot Net Articles 1-4 Start Here
"Do you hide in Happy Hour?" Marillion Clutching At Straws
|
|
|
|
|
I've had this problem before. I don't know WHY it surfaced... It seems that a process has hold of the libdll file, so it can't be overwritten.
When I see this problem, I close down VS.net, remove libdll from the folder that mainexe is compiled into.
When I startup VS.net and open the project again, I don't see this problem again.
|
|
|
|
|