|
Inherit your class from TextBox Overrid OnPaint and set
ControlStyle to UserPaint use The Following Class as start
public class TextBoxEx :TextBox
{
private Color borderColor;
public TextBoxEx()
{
this.SetStyle(ControlStyles.UserPaint,true);
this.BorderStyle=BorderStyle.FixedSingle;
borderColor=Color.Red;
}
public Color BorderColor
{
get
{
return borderColor;
}
set
{
borderColor=value;
}
}
protected override void OnBorderStyleChanged(EventArgs e)
{
this.BorderStyle=BorderStyle.FixedSingle;
base.OnBorderStyleChanged (e);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
ControlPaint.DrawBorder
(e.Graphics,e.ClipRectangle,borderColor,ButtonBorderStyle.Solid);
}
MCAD
|
|
|
|
|
void DrawComplexNumber(double re_, double im_)
{
//What code in here creates a Graphics obj?
}
thanks
|
|
|
|
|
Al drawing should be done in an OnPaint Handler. OnPaint gets called when the form/control needs to be painted again (ew.g. another window was moved above it)
If you call DrawComplexNumer from an OnPaint handler, simply pass the Graphics object as additional parameter.
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Where you want to draw form,PictudeBox?
MCAD
|
|
|
|
|
|
i mean the surface you want to draw on it?
MCAD
|
|
|
|
|
private void complexA_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen cmplxAPen = new Pen(Color.Crimson);
//
try {
double valAReal;
double valAComplex;
valAReal = Convert.ToDouble (this.textComplexAReal.Text);
valAComplex = Convert.ToDouble(this.textComplexAComplex.Text);
//HOW TO DEFINE THIS FUNCTION?
DrawComplexNumber(valAReal, valAComplex);
}
catch {
MessageBox.Show("Invalid Complex A Number", "Error!");
}
}
|
|
|
|
|
You need to modify DrawComplexNumber Function let its Decleraion like
DrawComplexNumber(Graphics g ,double re_, double im_)
{
//Your implementation
//g.DrawLine(.......)
}
and in complexA_OK_Click call it like
DrawComplexNumber(g,valAReal, valAComplex);
where g =this.CreateGraphics()
MCAD
-- modified at 16:32 Monday 5th September, 2005
|
|
|
|
|
Mohammed-- got it to work! thanks
However each time I input values to the TextBox and click the "OK" button event, it will not erase the previous line that was drawn. So each set of coords are all drawn on the graph.....?
Invalidate()? Where?
|
|
|
|
|
You can Call Clear method of Graphics object
g.Clear(color); set color to the background color
but note that this clear all not onley the line you draw
if you want to clear onley the line
Pen p=new Pen(new SolidBrush(this.BackColor));
g.DrawLine(p,x1,y1,x2,y2);
MCAD
|
|
|
|
|
I am using file watcher and a timer in a windows service and i want that timer_elapsed function should be called only when any file sytem watcher event is not working.i think it can be done using threading if i will assign lowest priority to the timer_elapsed thread.but i am not able to do it.
can anybody can tell me how to do it in C#.
|
|
|
|
|
I would use something as simple as a static variable as a counter. Increase the counter when a watcher event starts, and decrese it when it ends. Check the counter in the timer, and only do anything if the counter is zero.
---
b { font-weight: normal; }
|
|
|
|
|
In C# the easiest way to accomplish this is to use a lock on an object.
private static object sLock = new object();
private void Timer_elapsed(object source, EventArgs e)
{
lock (sLock)
{
}
}
private void FileWatcher_event(object source, EventArgs e)
{
lock (sLock)
{
}
}
any code in the lock blocks is protected from multiple threads accessing it at the same time. I do something similar with the timer that I wrote: http://www.codeproject.com/dotnet/ABTransClockArticle.asp[^]
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Working with a encryption app that stores data in a xml-file.
When i encrypt "Test" it looks like below:
1/2 6 square D
when i store it in the xml file it reads:
8
What can be the problem... should i encode it in some special way?
Below is some of my code. As you see iam using Encoding.Default... UTF-8.
Creates the xml file:
XmlTextWriter initXmlWriter = new XmlTextWriter (_strFilePath+" neocodes.xml", Encoding.Default);
initXmlWriter.Formatting = Formatting.Indented;
initXmlWriter.WriteStartDocument(false);
Get the xml file into a xml node list:
_xmlNeoCodes.Load(_strFilePath+" neocodes.xml");
_xnlCodes = _xmlNeoCodes.GetElementsByTagName("code");
Read node:
tempNode = _xnlCodes[i].ChildNodes;
tempstring = tempNode[3].InnerXml.ToString();
Johan
|
|
|
|
|
How to make Intelligent datagrid like yahoo messenger address tab. When we type any word first letter like
In Datagrid Column name is Name it has different name like
Muhammad Waqas Butt
Muhammad Sheraz Butt
Saad Butt
Aarij Butt
So when we type M then it show and select the record and then type u it show only record which are starting from M and second word u.
Any Idea? In C#.Net
|Muhamad Waqas Butt|
waqasb4all@yahoo.com
www.sktech.freewebspace.com
|
|
|
|
|
search for Asynchronous Javascript and XML (AJAX) on google...
|
|
|
|
|
Buddy I am looking for resource WinForm C#.Net not asp.net.
|Muhamad Waqas Butt|
waqasb4all@yahoo.com
www.sktech.freewebspace.com
|
|
|
|
|
How to make Intelligent datagrid like yahoo messenger address tab. When we type any word first letter like
In Datagrid Column name is Name it has different name like
Muhammad Waqas Butt
Muhammad Sheraz Butt
Saad Butt
Aarij Butt
So when we type M then it show and select the record and then type u it show only record which are starting from M and second word u.
Any Idea? In C#.Net
|Muhamad Waqas Butt|
waqasb4all@yahoo.com
www.sktech.freewebspace.com
|
|
|
|
|
Greetings,
I am trying to get the pixel width of a string (using Windows forms default font) so that I can set the .Width property of a button as needed. I'm looking at this article:
http://www.codeproject.com/cs/media/measurestring.asp
But like many of the other responders I can't figure out how to call this thing. What I WOULD LIKE to do is simply have something like this:
private int iWidth;
iWidth = MeasureDisplayStringWidth("some string", Control.DefaultFont)
button1.Width = iWidth;
I cannot understand how to wire up a paint event and get back the int value out of the function in this article. I'm trying:
button1.Paint += new PaintEventHandler(button1_Paint);
...
private void button1_Paint(object sender, PaintEventArgs e)
{ MeasureDisplayStringWidth(e, ((Button sender).Text, Control.DefaultFont); }
this doesn't build and I can't figure out how to get the int value out of MeasureDisplayStringWidth.
Any tips would be appreciated. Thanks.
|
|
|
|
|
I found an example of the usage of MeasureDisplayStringWidth here:
http://www.thecodeproject.com/cs/miscctrl/BindSortAutosizing.asp
|
|
|
|
|
I've used VS2003 Wizard to create sqlDataAdapter, stored procedures, and dataset on my application. I can search and update fine but Insert has error unless I perform a search or update prior to my insert. Any ideas on how to work around this without rewriting the database?
Code Snippet ================================================================
static void Main()
{
Application.Run(new Form1());
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
//Initialize Staff Physician Screen
SetupStaffPhysician();
menuItem2.Enabled = false;
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
//Exit Application
Application.Exit();
}
private void SetupStaffPhysician()
{
panel1.Visible = true;
this.comboBox1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedIndex", this.dsStaffPhysicians1, "tblStaffPhysicians.docLicenseState"));
}
private void ClearStaffPhysicians()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
comboBox1.SelectedIndex = 0;
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.SelectCommand.Parameters["@Param2"].Value = textBox3.Text;
dsStaffPhysicians1.Clear();
sqlDataAdapter1.Fill(dsStaffPhysicians1);
}
private void btnReset_Click(object sender, System.EventArgs e)
{
this.dsStaffPhysicians1.Clear();
ClearStaffPhysicians();
}
private void btnUpdate_Click(object sender, System.EventArgs e)
{
this.BindingContext[dsStaffPhysicians1, "tblStaffPhysicians"].EndCurrentEdit();
sqlDataAdapter1.Update(dsStaffPhysicians1);
sqlDataAdapter1.Fill(dsStaffPhysicians1);
}
private void btnInsert_Click(object sender, System.EventArgs e)
{
this.BindingContext[dsStaffPhysicians1, "tblStaffPhysicians"].AddNew();
ClearStaffPhysicians();
}
private void btnCommit_Click(object sender, System.EventArgs e)
{
this.BindingContext[dsStaffPhysicians1, "tblStaffPhysicians"].EndCurrentEdit();
sqlDataAdapter1.Update(dsStaffPhysicians1);
}
}
}
"She folds her legs...in doing so I glimpse Xanadu."--Gilby
|
|
|
|
|
how are you Dudes ?
I have one probelm in my application i need to display multiple lines in richtextbox but each line has its own attributes of new font , size and new color how can i manage this in the richtextbox knowing that i succeeded to do that using the following code but there was a small probelm .
<br />
int index = richtextbox1.Find(string message , 0 , message.length);<br />
richtextbox1.select(index , 0 , message.length);<br />
richtextbox1.selectionFont = new font(font attributes goes here of the new font);<br />
richtextbox1.selectionColor = Color.Blue
But with the above code it will certainly manage every new written line with its new font and color attributes but if i entered two or more sentences similar to each other the first one of them will be only changed and the newly entered message which is similar to the previous will have the defaul color and font.
So the question is :
How can i inset multiple lines of texts each of which with different font and color attributes.
Miss With The Best And Die Like The Rest
|
|
|
|
|
Hi
Ive not really used richtextboxes, but looking at your code, i think you just need to change the start position in richtextbox1.Find, and then use a loop:
<br />
int pos = 0;<br />
while(pos < richtextbox1.TextLength)<br />
{<br />
int index = richtextbox1.Find(message, pos, RichTextBoxFinds.None);<br />
if(index == -1)<br />
break;<br />
richtextbox1.Select(index, message.Length);<br />
richtextbox1.SelectionFont = new Font(...);<br />
richtextbox1.SelectionColor = Color.Blue;<br />
pos = index + message.Length;<br />
}<br />
Hope this helps
Philip Cole
|
|
|
|
|
Hi,
i am using a dll in one of its function i am passing out object parameter;
the parameter returned is shown as of type int32 perhaps it is returning a pointer to image,
i know that the dll is returning an image, perhaps pointer to varient image
please sujjest how to get this image, or can it be casted to stream & how, cause i want to display the image in picturebox;
Thanks Hope i will get help fast
Regards
Arus
|
|
|
|
|
Do you know exactly what your function is returning? If it's an HBITMAP (a Win32 handle to a bitmap) there's Image.FromHbitmap to convert it to a .NET Image object that you can use in a PictureBox . But it could also bit a pointer to a buffer with the bitmap data (header, color table and so on)... or a JPEG image...
First you need to know exactly what it is, before being able to convert it.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|