Here is some code that represents the problem(two files):
I've overriden the onPaint and onPaintBackground of the control and the form so no painting should be done, but yet a black rectangle shows up where the button is suppose to be. If you uncomment the WndProc's return that is commented(handles WM_PAINT), then the region isn't black, but isn't being painted(until it is resized or moved)... I also do not have WS_CLIPCHILDREN set, which would seem the cause of the problem. This is a very odd to me and can't find any information about how windows.forms handles painting... and its driving me nuts(cause my application is useless with black boxes everywhere)... I hope someone can help.
Thanks in advance.
[UserControl1.cs]
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace jButton
{
public class UserControl1 : System.Windows.Forms.Button
{
private System.ComponentModel.Container components = null;
public UserControl1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
protected override void OnPaint(PaintEventArgs e) {}
protected override void OnPaintBackground(PaintEventArgs e) {}
}
}
----------------------------------------------------------
[Form1.cs]
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Test1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private jButton.UserControl1 userControl11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.SetStyle(ControlStyles.UserPaint, true);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.userControl11 = new jButton.UserControl1();
this.SuspendLayout();
//
// userControl11
//
this.userControl11.Location = new System.Drawing.Point(24, 16);
this.userControl11.Name = "userControl11";
this.userControl11.Size = new System.Drawing.Size(160, 144);
this.userControl11.TabIndex = 0;
this.userControl11.Text = "crapola";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.userControl11);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
//this.Region.MakeInfinite();
this.Region = new Region();
this.Region.MakeInfinite();
this.SetStyle(ControlStyles.UserPaint, true);
this.UpdateStyles();
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = new CreateParams();
cp = base.CreateParams;
//cp.ClassStyle = jGui.Win32.CS_DBLCLKS;
//cp.Style = jGui.Win32.WS_VISIBLE | jGui.Win32.WS_SYSMENU | jGui.Win32.WS_OVERLAPPED;
//cp.ExStyle = jGui.Win32.WS_EX_CLIENTEDGE;
return cp;
}
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x000F)
{
//return;
}
base.WndProc (ref m);
}
protected override void OnPaint(PaintEventArgs e)
{
//base.OnPaint (e);
}
protected override void OnPaintBackground(PaintEventArgs p)
{
//base.OnPaintBackground(p);
}
}
}
---
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.