Problem with 2 forms

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2008
Posts: 1,908
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 273
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Problem with 2 forms

 
0
  #1
Dec 21st, 2008
I like to write a screen capture utility. Plan : have a master control form, let it make a second transparant form on wich a selection rect can be drawn, copy the screen under the rectangle to a Bitmap with Grapics.CopyFromScreen.
Here is the essential code I have so far:

  1. public partial class Master : Form
  2. {
  3. private Form Foil;
  4.  
  5. public Master()
  6. {
  7. InitializeComponent();
  8. Foil = new TransparantFoil(this);
  9. Foil.Hide();
  10. }
  11.  
  12. private void Button_Click(object sender, EventArgs e)
  13. {
  14. this.Hide();
  15. Foil.Show();
  16. }
  17. }
  18.  
  19. public partial class TransparantFoil : Form
  20. {
  21. private Form _master;
  22.  
  23. public TransparantFoil(Form M)
  24. {
  25. InitializeComponent();//WindowState= Maximized Opacity=0.4
  26. _master = M;
  27. }
  28.  
  29. private void TransparantFoil_Click(object sender, EventArgs e)
  30. {
  31. this.Hide();
  32. _master.Show();
  33. }
  34. }

The only thing I wanted to do here is switching between the two forms, by clicking a button in Master and clicking on Transparant.
The problem is that Transparant sometimes thinks that the TaskBar is the main screen and I can't figure out why.
Anyone any suggestions? Is my basic strategy totally wrong?
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Problem with 2 forms

 
0
  #2
Dec 21st, 2008
Logic looks ok to me, my only question is is "_master" always what you think it should be? Im wondering if perhaps instead of overriding the creation it somehow isnt using it so _master ends up null or something and that perhaps this is causing the effect you see
Last edited by LizR; Dec 21st, 2008 at 10:17 am.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,908
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 273
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: Problem with 2 forms

 
0
  #3
Dec 22nd, 2008
LizR, I tried your suggestion and tested on null, but it never occurred. Finally I found that the location property of a form is relative to the container in which it is created. I still can explain it but if I swap lines 14 and 15 in the code above it seems to work!
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Problem with 2 forms

 
0
  #4
Dec 22nd, 2008
I knew the location would likely be relative, but that didnt sound like the behavior you got. Let alone swapping the show and hide round.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,908
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 273
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: Problem with 2 forms

 
0
  #5
Dec 22nd, 2008
I think the second form gets teh coordinates of the hidden form as its base. And Hide means to me something like put the location of this form into oblivion(screen coordinates of millions and more or something like that)
So when master form is Hidden first teh Transparent form tries his best and shows itself in the Taskbar.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Problem with 2 forms

 
0
  #6
Dec 22nd, 2008
only at creation, after that it shouldnt move.. unless theres something else going on?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,908
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 273
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: Problem with 2 forms

 
0
  #7
Dec 22nd, 2008
I will post a new thread if I can find that "something else", until then I consider thisone as solved...
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC