|
showing some code (and not triple posting ) would certainly help get you an answer quicker.
|
|
|
|
|
ok that is the whole code
i think that would help
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;
namespace MyCustomControls
{
///
///
public class custom1:System.Windows.Forms.Button
{
private Point p1 ;
private Point p2 ;
private Point p3;
private Point p4;
private Point p5;
private Point p6;
private Point p7;
private Point p8;
private Point p9;
private Point p10;
private Point p11;
private Point p12;
private Point[] points;
int x;
int y;
int z;
int a;
private System.Drawing.Drawing2D.LinearGradientBrush lgb ;
private System.Drawing.Drawing2D.GraphicsPath gb;
private System.Drawing.Color color1;
private Color color2 ;
private Color color3;
private Graphics g;
private Rectangle rec;
private Pen pen;
public custom1()
{
Init();
}
public void Init()
{
x = this.Width ;
y = this.Height;
z = x / 2;
a = y / 2;
color1 = Color.Silver;
color2 = Color.White;
color3 = Color.Navy;
p1 = new Point(1, 0);
p2 = new Point(x-1, 0);
p3 = new Point(x-1,1);
p4 = new Point(x, 1);
p5 = new Point(x, y-1);
p6 = new Point(x-1, y-1);
p7 = new Point(x-1, y);
p8 = new Point(1, y);
p9 = new Point(1, y-1);
p10 = new Point(0, y-1);
p11 = new Point(0, 1);
p12 = new Point(1, 1);
points = new Point[12]{p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12};
lgb = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height),Color.FromArgb(253,253,253),Color.FromArgb(201,200,220),90.0f);
gb = new GraphicsPath();
float[] relativeIntensities = {0.0f, 0.008f, 1.0f};
float[] relativePositions = {0.0f, 0.32f, 1.0f};
Blend blend = new Blend();
blend.Factors = relativeIntensities;
blend.Positions = relativePositions;
lgb.Blend = blend;
rec = new Rectangle(0, 0, this.Width, this.Height);
//events
// this.Click+=new EventHandler(custom1_Click);
// this.MouseEnter+=new EventHandler(custom1_MouseEnter);
// this.MouseLeave+=new EventHandler(custom1_MouseLeave);
// this.MouseDown+=new MouseEventHandler(custom1_MouseDown);
// this.MouseUp+=new MouseEventHandler(custom1_MouseUp);
//
}
protected override void OnPaint(PaintEventArgs e)
{
g = e.Graphics;
g.FillPolygon(lgb, points);
gb.AddLines(points);
this.Region = new Region(gb);
//base.OnPaint (e);
}
public enum States
{
Normal,
MouseOver,
Pushed
}
States state;
protected override void OnMouseEnter(EventArgs e)
{
state = States.MouseOver;
this.Invalidate(rec);
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(System.EventArgs e)
{
state = States.Normal;
this.Invalidate(rec);
base.OnMouseLeave(e);
}
protected override void OnMouseDown
(System.Windows.Forms.MouseEventArgs e)
{
// do nothing if pressed not the left button of mouse
if ((e.Button & MouseButtons.Left) != MouseButtons.Left) return;
if (rec.Contains(e.X, e.Y))
{
state = States.Pushed;
// button receives an imput focus
this.Focus();
}
else state = States.Normal;
this.Invalidate(rec);
base.OnMouseDown(e);
}
protected override void OnMouseUp
(System.Windows.Forms.MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
state = States.Normal;
this.Invalidate(rec);
base.OnMouseUp(e);
}
}
}
|
|
|
|
|
hi,
i am doing a custom control inherits from button but has diffrent shape
but every time i try to put it in a form and mouse over on it, it disappeared
i handled all the methods that can be handled in it but nothing
can any one help me plz?
|
|
|
|
|
|
i want to syncronizse between windows clock and another device which i test that has its own clock.
i'll read the Real Time Clock Of the device(through RS232) and calculate th offset between them and update the offset to whatever i want
does enyone knows how can i do it?
|
|
|
|
|
how does the pc and the device communicate? how do you obtain time from the device? does the device have a "time" or just tick-counts?
there are no facts, only interpretations
|
|
|
|
|
Hi all,
I want to write a background application that checks certain conditions periodically at a configurable period (e.g. 10sec). What is the best aproach to acheive this ? by Timer or by a looping thread or other better method ? The background application should consume small CPU power so that it won't affect the applications at the foreground.
Thanks
Patrick
|
|
|
|
|
A timer would be the best approach, cause a looping thread will definitely consume CPU power.
www.troschuetz.de
|
|
|
|
|
Yeah, use a timer or if you have a problem with that use the Thread.Sleep(So many milliseconds); statement.
Salil Khedkar [^]
|
|
|
|
|
Hi all,
how can we add history of recently viewed items into our application's menu. I have developed an interface, i want to keep track of all the recently viewed file names in my File menu (atmost 5).
is it easy to implement it or should we have to do some rigourous work...?
any ideas or suggestions?
thanks in advance,
Suman
|
|
|
|
|
You'll have to define a container where you store the names respectively the paths of your recently viewed files. This could be a simple array or maybe some more complex container.
To your MainMenu add a MenuItem which is for example named "Recently Files". In the PopUp event of this MenuItem add a MenuItem for each file in your container. At last write an event handler for Click events of the several MenuItems and load the specific file.
www.troschuetz.de
|
|
|
|
|
|
Hi guys,
thanks for ur advices and suggestions and they did help me in coding my own program.
thanks,
Suman
|
|
|
|
|
Does anyone know how to change the font size of the column header in a ListView?
I'm wrinting an App in C#
Have a great coding day.
Regards,
Tony D. Abel
|
|
|
|
|
There is a nice article on customizing the ListView located here[^]. Basically you will see that he has subclassed the NativeWindow . There are a few important steps; in particular, you must assign the handle of the subclassed native window to that of the handle to the header control's handle. Also, you will need to override the WndProc and watch for WM_SETFONT (0x0030). This will allow you to specify your own Font instance and then assign the WParam of your message the handle of your newly created font (call ToHfont() on your Font object), then obviously you will want to call base.WndProc(ref m); so your changes are propagated. The following P/Invoke signature will be needed:
[DllImport("User32.dll",CharSet = CharSet.Auto,SetLastError=true)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
- Nick Parker My Blog | My Articles
|
|
|
|
|
Can someone point me to a 'good' site that outlines good naming conventions for objects and variables etc. for both c# and VB? Preferably a microsoft site. Doing a search for this brings up nothing substantial. Thanks!
SN
|
|
|
|
|
|
|
Hi
I have a form which is being displayed, and from my class I would like to be able to set control values.
In VB6 I would have done this by simply frmMain.txtName = "John", however, in C# doesn't seem quite so easy. What am I doing wrong?
Thanx
|
|
|
|
|
How can we tell you if you don't show any code?
|
|
|
|
|
Well, your question is rather nebulous, in particular because assuming you had a Form class instance called frmMain , you could simply access the control and then specifically the specific property of the control (this may be the part you were missing) like this:
frmMain.txtName.Text = "John";
Also, if you are referencing the control from within the class it is defined, you can change properties as such:
this.txtName.Text = "John";
txtName.Text = "John";
Hope this helps.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi Nick
Thanks for taking the time to help, and sorry for the lack of detail. I have a form - frmMain - which is my main window. Within frmMain (ie the code behind the form), I have a function called Main(), within this function I load the form using the following code:
static void Main()
{
Application.Run(new frmMain());
}
This Main() function is set as my startup function therefore by default.
On this form, I have some textboxes, relating to a specific job. I am trying to keep all the processes that relate to this job in it's own class. So populating the fields on the form, with values from the database would be a method in the class.
But, my problem seems to be accessing the form controls, from the class.
Not sure if this makes the situation any clearer. Is it because the form has to be instantiated in the class? Or do the form controls need to be static in order for them to be visible to the class? Or am I barking completely up the wrong tree?!?
Thanks again.
M
|
|
|
|
|
isittheweekendyet wrote:
Not sure if this makes the situation any clearer.
Yes, this helps. First it's important to understand that the following are identical.
static void Main()
{
Application.Run(new frmMain());
}
static void Main()
{
frmMain frm = new frmMain();
frm.ShowDialog();
}
So where are you trying to access a controls property? This is a quick example:
public class test : System.Windows.Forms.Form
{
Button b;
Label l;
public test()
{
l = new Label();
this.Controls.Add(l);
b = new Button();
b.Location = new Point(20, 20);
b.Click += new EventHandler(bClick);
this.Controls.Add(b);
}
public static void Main()
{
Application.Run(new test());
}
private void bClick(object sender, EventArgs e)
{
l.Text = "Hello";
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
I am accessing the controls as follows (continuing with your example):
public class test : System.Windows.Forms.Form
{
Button b;
Label l;
Client myClient = new Client();
public test()
{
l = new Label();
this.Controls.Add(l);
b = new Button();
b.Location = new Point(20, 20);
b.Click += new EventHandler(bClick);
this.Controls.Add(b);
}
public static void Main()
{
Application.Run(new test());
}
private void bLoadClientClick(object sender, EventArgs e)
{
myClient.LoadClient();
myClient.DisplayClient();
}
}
public class Client
{
string strName = "";
string strAddress = "";
string strTelephone = "";
public void DisplayClient()
{
txtName.Text = strName;
txtAddress.Text = strAddress;
txtTelephone.Text = strTelephone;
}
public bool LoadClient()
{
...
...
}
}
That type of thing.
Thanks
|
|
|
|
|
I have an application that accesses a password protected database. I know that is it not recommended placing the password within the code of the application that accesses the database. Especially with the ability to decompile .NET.
What are some recommended ways/best practices of handling the password storage on the user's PC but preventing the user from seeing the password?
|
|
|
|