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:

public partial class Master : Form
{
    private Form Foil;

    public Master()
    {
        InitializeComponent();
        Foil = new TransparantFoil(this);
        Foil.Hide();
    }

    private void Button_Click(object sender, EventArgs e)
    {
        this.Hide();
        Foil.Show();
    }
}

public partial class TransparantFoil : Form
{
    private Form _master;

    public TransparantFoil(Form M)
    {
        InitializeComponent();//WindowState= Maximized Opacity=0.4
        _master = M;
    }

    private void TransparantFoil_Click(object sender, EventArgs e)
    {
        this.Hide();
        _master.Show();
    }
}

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?

Recommended Answers

All 6 Replies

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

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!

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.

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.

only at creation, after that it shouldnt move.. unless theres something else going on?

I will post a new thread if I can find that "something else", until then I consider thisone as solved...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.