Nick_M123

I am creating an application for a Tablet PC that has a flash movie playing in the background and looks for input from the user (from a writing area I have defined in a groupbox on the main form). I am curious how to make this groupbox invisible but still usable so that I can show it and unshow it without anyone knowing the difference and it will still collect the pen input.

Thanks!



Re: Windows Forms Designer How to create and Invisible Groupbox

DaveQuick

Have you considered using a panel instead of a groupbox You can set the background color to the form's background color and set the border to 'none'.

If you need the groupbox's title and border you could also put the groupbox in a panel and show and hide the panel.






Re: Windows Forms Designer How to create and Invisible Groupbox

Nick_M123

I thought about using a different control but there is nothing that I have seen that will allow me to have transparency through to the flash object in the background. Any time I set the transparency key or try playing with setting like that, it just becomes transparent to the entire form, not transparent to the flash object.





Re: Windows Forms Designer How to create and Invisible Groupbox

DaveQuick

It sounds like I'm missing some key information about your problem.

Why is transparency to the form and not just the flash object a problem If the flash object is visible, is on the form and the group box or panel has a transparent background, anything behind it, including the flash object, should be visible, right






Re: Windows Forms Designer How to create and Invisible Groupbox

Nick_M123

While it seems like it should be working... its not. To see what I'm talking about: open a new C# windows application, put a flash object in the main form so that it covers the entire form background and then put a groupbox over it and try to set the transparency. I have tried a variety of things to get it to just show the flash object but nothing has worked so far. I appreciate your help in this.





Re: Windows Forms Designer How to create and Invisible Groupbox

DaveQuick

I think I understand the situation now. You're putting a flash object on the form as/or in a winform control and making the control large enough to cover the entire form, right

Unfortunately, transparent backgrounds in winforms controls aren't truly transparent, they just copy the part of the form's background that they would normally cover up. This means they are not transparent to other controls on the form.

I've never tried to make controls truly transparent myself, but maybe someone else here has.

One possible work around is to create a second form in your solution with its Opacity property set to 0% and with no borders or title bar. Put your input controls on the transparent form and position it over the form that contains the flash object. You can easily Show or Hide it and it will allow your flash object and any other controls on the main form to show through. It might be a little more work to coordinate events between the two forms, but it shouldn't be too bad.






Re: Windows Forms Designer How to create and Invisible Groupbox

DaveQuick

In thinking about this a little more, you will probably want to create your transparent form with a title bar and the same border style and window controls (close, maximize, etc.) that your main form has. When you've done that you can just make your transparent form the same size as your main form. This will give you a way to capture the user's interactions with the transparent form and pass them along to the main form.






Re: Windows Forms Designer How to create and Invisible Groupbox

DaveQuick

An additional thought. You may need to set the Opacity property to 1% or 2%. I seem to remember that setting it to 0% made it act as though the form wasn't there at all, but a low value still accepted input and was virtually invisible.




Re: Windows Forms Designer How to create and Invisible Groupbox

Nick_M123

I tried to create a form within a form using the MDI functions but the only thing I get it to do is Form2 replaces the contents of Form1 and then nothing else works. I am not quite sure how to code a new form (Form2) to appear at the bottom of the parent form (Form1) that is floating on top of the contents of the parent form. Have any suggestions or examples






Re: Windows Forms Designer How to create and Invisible Groupbox

DaveQuick

I've never tried it using MDI.

I used independent forms. I used a base form to display the content and launched the transparent form from the base form. The transparent form is the same size as the base form and is positioned directly over it. I added a BaseForm property to the transparent form to give me a reference back to the base form. This made it easy to move or resize the base form if the user moves or resizes the transparent form. I think I had to make sure the transparent form's opacity was greater than 0 in order for it to receive mouse and other input events.

This is a work around and not a perfect solution. One side effect of this approach is that the title bar doesn't look quite right. The transparent form has the input focus but it is transparent, so you see the underlying base form's title bar, which is not the right color because it doesn't have the focus.

Here's a very basic code example using two forms; baseForm (the base form) and clearForm (the transparent form).

public partial class baseForm : Form
{
ClearForm clearForm = new ClearForm();

public baseForm()
{
InitializeComponent();
}


public void MoveForm(int left, int top)
{
this.Left = left;
this.Top = top;
}


private void baseForm_Load(object sender, EventArgs e)
{
clearForm.BaseForm = this;
clearForm.Left = this.Left;
clearForm.Top = this.Top;
clearForm.Height = this.Height;
clearForm.Width = this.Width;
clearForm.BringToFront();
clearForm.Show();
}

private void baseForm_Activated(object sender, EventArgs e)
{
clearForm.Focus();
}
}


public partial class ClearForm : Form
{

public ClearForm()
{
InitializeComponent();
}

private void ClearForm_Move(object sender, EventArgs e)
{

if (this.BaseForm != null)
{
this.BaseForm.Left = this.Left;
this.BaseForm.Top = this.Top;
}
}

private baseForm baseForm;

public baseForm BaseForm
{
get { return baseForm; }
set { baseForm = value; }
}

private void ClearForm_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}

private void ClearForm_Resize(object sender, EventArgs e)
{
if (this.BaseForm != null)
{
this.BaseForm.Width = this.Width;
this.BaseForm.Height = this.Height;
}
}

}






Re: Windows Forms Designer How to create and Invisible Groupbox

Nick_M123

This works pretty much exactly as I need it to except that I need it to be docked to the bottom of the window not the top. So for example:

this.baseForm.Bottom = this.Bottom;
this.baseForm.Right = this.Right;

does not work. Know any ways of getting around this or how to make it so that the base form stays the same size and the child form is a smaller so it appears to be docked on the bottom

Thanks for all your help so far, I really do appreciate it.





Re: Windows Forms Designer How to create and Invisible Groupbox

DaveQuick

You're welcome. In order to keep things simple, my example assumes you want to make the transparent form cover the base form entirely. Handling user events gets a lot more complicated once you start making one larger than the other. I expect you could make it work but the code will get messy and complicated pretty quickly.

Here's another approach that may help. This is still a work around, but approaches the problem from a different direction.

Add a user control to your project. I call it ClearControl in the following code. Making the modifications shown below will create a user control that has a real transparent background. Add a panel control to the design surface of this user control, dock it to fill the control, and set its background to transparent. You should be able to use the panel to gather your input. Once it's compiled, you can place an instance of the ClearControl on your base form in the form designer and make it any size you want.

The downside to this approach is that I have no idea how well it will work with an animation playing in the background. I do know that this approach doesn't support double buffering.

public partial class ClearControl : UserControl
{
public ClearControl()
{
InitializeComponent();
}

protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}

protected override void OnPaintBackground(PaintEventArgs pevent)
{
// Prevents background painting
}

protected override void OnPaint(PaintEventArgs e)
{
// Put custom drawing code here if needed. Will appear over controls behind this control.
}

}






Re: Windows Forms Designer How to create and Invisible Groupbox

Nick_M123

I think we were in the right direction before if I could just find out how to offset the child form so that it is docked in the bottom or at least appears there. For now it just appearing in the correct place would be more then fine for me.


// changing this does nothing
clearForm.Left = this.Left;
// changing this does nothing
clearForm.Top = this.Top;
// I can minus the value so the form becomes shorter but doesnĄ¯t do anything other then that
clearForm.Height = this.Height;
// Dont need to change this
clearForm.Width = this.Width;

I also tried using the DockStyle command to make it dock to the bottom but no luck. Any thoughts






Re: Windows Forms Designer How to create and Invisible Groupbox

DaveQuick

Sorry to take so long to reply. Our power went out last Thursday and just came back on a little while ago.

The DockStyle property won't have any effect, since neither form is a child of the other.

When you say that you want the clearForm to be docked at the bottom of the baseForm, do you mean that the clearForm should be the same height as the client area of the baseform and the top of the clearForm should be positioned at the top of the client area of the baseForm This would position it below the baseForm's title bar and menu bar, if it has one.

I'm assuming you want the width of the clearForm to be the same as the width of the baseForm, right






Re: Windows Forms Designer How to create and Invisible Groupbox

Nick_M123

Dont worry about it taking so long, I completely understand. I'll try to do a horrible drawing so you understand what I am talking about (I realize now that I should have done this in the beginning)

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bb bb
bb bb
bb bb
bb bb
bb bb
bb bb
bb bb
bb bb
bb bb
bb bb
bb bb
bb bb
bbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccbb
bbcc ccbb
bbcc ccbb
bbcc ccbb
bbcc ccbb
bbcc ccbb
bbcc ccbb
bbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccbb

Forgive the horrible drawing as I know posting this will screw up the formating but as you can see the child form will be at the bottom within the parent form (since the child form will be transparent you will never be able to tell where it is)

Questions, thoughts, ideas