WinForms child form to another process - c#

I'm trying to create child form on other process form without activation, everything is ok except that my form appearing in front of screen when showing - after f.Visible=true - but i need to keep both of them somewhere behind.
Here's code:
public class OSD {
public class OSD_form:Form {
protected override bool ShowWithoutActivation {
get { return true; }
}
protected override CreateParams CreateParams {
get {
CreateParams p=base.CreateParams;
//p.Style |= 0x40000000; // WS_CHILD
p.ExStyle|=0x8000000; // WS_EX_NOACTIVATE
p.ExStyle|=0x00080000; // WS_EX_LAYERED
p.ExStyle|=0x0020; // WS_EX_TRANSPARENT
return p;
}
}
}
private OSD_form f=null;
public IntPtr AttachedTo=IntPtr.Zero;
public OSD() {
f=new OSD_form();
f.FormBorderStyle=FormBorderStyle.None;
f.ShowInTaskbar=false;
}
public void Show() {
long l2=winapi.GetWindowLong(f.Handle,winapi.GWL_EXSTYLE);
l2|=winapi.WS_EX_LAYERED;
l2|=winapi.WS_EX_TRANSPARENT;
winapi.SetWindowLong(f.Handle,winapi.GWL_EXSTYLE,new IntPtr(l2));
winapi.SetLayeredWindowAttributes(f.Handle,0,(255*90)/100,winapi.LWA_ALPHA);
window w=new window(AttachedTo);
f.Width=160;
f.Height=60;
f.Left=w.Client.Left+4;
f.Top=w.Client.Top+4;
f.Show(new WindowWrapper(AttachedTo));
f.Visible=true;
}
}

Related

How to increase the space between the bottom of the screen and Tab titles on Android using Xamarin Forms Shell?

I have used ShellRenderer but I am unable to get the code working to add an extra space between the bottom of the screen and the icons. Here is an image:
I need to increase the space between the bottom of the screen and the tab item titles.
Here is the code that I have tried:-
namespace MyProject.Droid.CustomRenderers
{
public class CustomShellRenderer : ShellRenderer
{
public CustomShellRenderer(Context context) : base(context)
{
}
protected override IShellTabLayoutAppearanceTracker CreateTabLayoutAppearanceTracker(ShellSection shellSection)
{
return new CustomBottomNavAppearance();
}
protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
{
return base.CreateShellSectionRenderer(shellSection);
}
protected override IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem)
{
return base.CreateShellItemRenderer(shellItem);
}
}
public class CustomBottomNavAppearance : IShellTabLayoutAppearanceTracker
{
public void Dispose()
{
}
public void ResetAppearance(TabLayout tabLayout)
{
}
public void SetAppearance(TabLayout tabLayout, ShellAppearance appearance)
{
for (int i = 0; i < tabLayout.ChildCount; i++)
{
var child = tabLayout.GetChildAt(i);
child.SetPadding(0, 0, 0, 20);
}
}
}
}
Let me know how can I fix this. Thanks!

Flickering on WinForm UI when Form is resized

When I resize the Winform UI (which has lot of child controls), flickering happens.
I used the below code, which is not working for Resize.
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style &= ~0x02000000;// Turn off WS_CLIPCHILDREN
return cp;
}
}
Create a Panel which will be the root of all children in your Form, and in your Form.OnResizeBegin() method, call Control.SuspendLayout(); in Form.OnResizeEnd(), call Control.ResumeLayout().
class MainForm: Form {
public MainForm()
{
this.Build();
}
void Build()
{
this.root = new Panel { Dock = DockStyle.Fill };
// create all controls and add them to root
this.Controls.Add( root );
this.ResizeBegin += (obj, args) => this.OnResizeBegin();
this.ResizeEnd += (obj, args) => this.OnResizeEnd();
}
void OnResizeBegin()
{
this.root.SuspendLayout();
}
void OnResizeEnd()
{
this.root.ResumeLayout( true );
}
Panel root;
}
Hope this helps.
I think you should change the ExStyle not the Style to get the double buffered effect
Also you should use |= in stead of &=
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // turn on WS_EX_COMPOSITED
return cp;
}
}
If there are still parts on your form that keep flickering then maybe this post can help

True Transparent Picturebox in VS2010

In my WinForm Application, I am needing to layer some images. However, I'm having trouble getting a transparent control to place the image in. I have done some research and came up with the following class:
public class TransparentPicture : PictureBox
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
// do nothing
}
protected override void OnMove(EventArgs e)
{
RecreateHandle();
}
}
This seems to work fine until I close Visual Studios and reopen the Solution. Then my controls all disappear in the designer. They show when I run the program, but I need them to show in designer too where I can continue to design my application.
I know this isn't everything I need to do, because these controls are always causing my program to freeze up for a few seconds and stuff.
So my question is..does anybody know where I can find code for a transparent control, or how to fix the one I've thrown together?
Make the TransparentPicture be a regular PictureBox, until an IsTransparent property is set to true.
Set the property to false on design time, and to true in FormLoad event (which will only happen when you actually run the application).
That way, on design time, they will behave as regular picture boxes, but when you run the application, they will become transparent.
public class TransparentPicture : PictureBox
{
public bool IsTransparent { get; set; }
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
if (this.IsTransparent)
{
cp.ExStyle |= 0x20;
}
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
if (!this.IsTransparent)
{
base.OnPaintBackground(e);
}
}
protected override void OnMove(EventArgs e)
{
if (this.IsTransparent)
{
RecreateHandle();
}
else
{
base.OnMove(e);
}
}
}
Then, on your FormLoad event, you should do:
for (var i = 0; i < this.Controls.Count; i++)
{
var tp = this.Controls[i] as TransparentPicture;
if (tp != null)
{
tp.IsTransparent = true;
}
}
Or if you only have a few:
tp1.IsTransparent = tp2.IsTransparent = tp3.IsTransparent = true;

Transparent label control is not refreshing properly

I've created a transparent label control and the transparency works great. However, I find when I update the control's Text field, the original Text doesn't clear before it paints the new text. So if I change the control's Text field several times, it soon becomes unreadable.
Any clues? Thanks!
public partial class TransLabel : Label
{
public TransLabel()
{
InitializeComponent();
this.SetStyle(ControlStyles.Opaque, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
this.Font = new Font("Franklin Gothic Book", 12f, FontStyle.Regular);
this.ForeColor = Color.White;
this.BackColor = Color.Transparent;
}
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
this.Invalidate(); // seems to have no effect
this.Refresh(); // seems to have no effect
}
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
//do nothing
}
protected override void OnMove(EventArgs e)
{
RecreateHandle();
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle = 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
}
Try changing your Text property to this:
public override string Text {
get {
return base.Text;
}
set {
base.Text = value;
if (this.Parent != null)
this.Parent.Invalidate(this.Bounds, false);
}
}
Since WinForms doesn't have true support for transparency, I think you have to invalidate the parent container.
Also, when inheriting a control, you usually don't have an InitializeComponent() method.

Opening a form in C# without focus

I am creating some always-on-top toasts as forms and when I open them I'd like them not to take away focus from other forms as they open. How can I do this?
Thanks
protected override bool ShowWithoutActivation
{
get
{
return true;
}
}
Override this property in your form code and it should do the trick for you.
It took me a few minutes using Adam's & Aaron's info above, but I finally got it to work for me. The one thing I had to do was make sure the form's Top Most property is set to false. Here is the code I used...
protected override bool ShowWithoutActivation { get { return true; } }
protected override CreateParams CreateParams
{
get
{
//make sure Top Most property on form is set to false
//otherwise this doesn't work
int WS_EX_TOPMOST = 0x00000008;
CreateParams cp = base.CreateParams;
cp.ExStyle |= WS_EX_TOPMOST;
return cp;
}
}

Categories

Resources