|
Hello everybody!
In my VS2003 Windows application, I created an instance of a Form during runtime.
I then whant to use it with the ShowDialog method.
everything worked fine, until I whanted to set the Witdh of the Form smaller then 112 pixel.
Can I block this limitation?
Thank you for your time.
Martin
|
|
|
|
|
There are minimum and maximum size properties, perhaps they are set ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How can I change the Frame color of a textbox?
|
|
|
|
|
I was wondering the same thing myself, and ended up just changing the BorderStyle to None, and drawing a simple border myself in the parent form/user control with a function like:
private void DrawTextBoxBorder(Graphics g)
{
Rectangle rectClient = myTextBox.ClientRectangle;
Rectangle rect = myTextBox.RectangleToScreen(rectClient);
rect.Offset(-1,-1);
rect.Width += 1;
rect.Height += 1;
Point ptClient = new Point(0,0);
Point ptScreen = PointToScreen(ptClient);
rect.Offset(-ptScreen.X, -ptScreen.Y);
g.DrawRectangle(Pens.SlateGray, rect);
}
|
|
|
|
|
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
|
|
|
|