|
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
|
|
|
|
|
In my project I have a lot of Date Time Picker Controls. But I have to set their MinDate property to First Day of Year, Max Date property to Last day of Year.
What is the easyist way to manage ?
Thank you.
|
|
|
|
|
If you have all controls inside the same form, this could work (in the form's constructor for example):
DateTime min = new DateTime(DateTime.Now.Year, 1, 1);
DateTime max = new DateTime(DateTime.Now.Year, 12, 31);
foreach(Control ctl in Controls)
{
DateTimePicker dtp = ctl as DateTimePicker;
if(dtp != null)
{
dtp.MinDate = min;
dtp.MaxDate = max;
}
} I hope this helps!
-- 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
|
|
|
|
|
Hi guys,
I tried many things while searching in the net for the answer but nothing seems to be helping. So maybe someone will have an idea for my problem.
I have faced this weirdest problem with C#.NET 2.0 (Windows Forms).
I have a class that creates an instance of a (Control) Slider() and passes an instance of CheckedListBox() to it. I set the size of CheckedListBox() to (160,100).
The Slider() it its constructor adds the CheckedListBox() that was passed to it to its Contols collection (this.Controls.Add(PassedControl);)
Then I add the Slider() to the form as well.
It looks something like this:
class a
{
using ...;
pulic a()
{
CheckedListBox box = new CheckedListBox();
box.Size = new Size(160,100);
myPanel x = new myPanel(box);
Contols.Add(x);
}
}
Where the myPanel looks something like this:
Class myPanel : System.Windows.Forms.Panel{
protected Control inner;
public myPanel(Contol _ctrl){
inner = _ctrl;
this.Controls.Add(inner);
}
}
My problem is that once the CheckedListBox() is added to the panel, it will change its size a bit. I guess .NET does this to actually make its size be x*Item.Height; so that it looks good or something.
Now, somewhere in the constructor for the myPanel I am trying to get the actual size of the CheckedListBox() and here the weird part starts.
It will always return 100. But the real size of it is 85.
The way I figured this out is this - add "int x = inner.size.height;" and then put a break right after this line.
You will see the both the x and inner.size.height are 100;
now - add the inner to quick watch and it will somehow recalculate the size and the inner.size.height will become 85 but x will remain 100.
Am I missing something or gone mad or what? But when I run this it will not return its real size unless I do the trick with quick watch for "inner". Both the inner.ClientSize and inner.Bounds return same 100 unless "quick watched".
Any ideas, this really is killing me now.
Thanks to all.
|
|
|
|
|
Hello, all!
I have a dll (TesteDLL.dll) written in C++:
#include "vtkRenderWindow.h"
extern "C"
{
__declspec(dllexport) vtkRenderWindow *DisplayDLL(void * a)
{
// build renderwindow and set window size
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->SetParentId(a);
return renWin;
}
}
(nevermind the vtkRenderWindow. It belongs to the Visualization Toolkit)
I want to use the DisplayDLL function in a C# program.
I used this: using System.Runtime.InteropServices;
this: [DllImport("TesteDLL.dll")]
public static extern vtkRenderWindow DisplayDLL(System.IntPtr a);
and this: System.IntPtr a = Form1.ActiveForm.Handle;
vtkRenderWindow renWin = DisplayDLL(a);
but I keep receiving the same message:
System.Runtime.InteropServices.MarshalDirectiveException: Can not marshal return value: The type definition of this type has no layout information.
What is the problem? I believe it has got something to do with the pointers...
Thank you,
Patrícia Gonçalves
|
|
|
|
|
You need to Marshal the information before using it.
1. Allocate memory in a buffer using the Marshal.AllocateCoTaskMem(bufferSize) or Marshal.AllocHGLobal(bufferSize).
2. Pass the buffer (not your local C# structure) to the dll function.
3. Convert the buffer to your local structure using Marshal.PtrToStructure(buffer, yourStruct)
4. Then use the 'yourStruct' in your C# code to access the handles etc.
5. Release the buffer that was allocated accordingly.
Look at the following articles explaining how to do it.
a. www.codeproject.com/csharp/csenumnetworkresources.asp
and
b. The Microsoft MSDN help. It can be found in the following dirctory tree under MSDN.
.NET Development->.NET Framework->Programming with the .NET Framework->Interoperating with Unmanaged Code->Interop Marshalling->Marshalling Data with Platform Invoke->Miscellaneous Marshalling Sample->Void Sample
I hope this helps
RobVai
|
|
|
|
|
Hi,
I have the follwing problem :
When doing field level validation, I use the following code the check whether a value entered in a text box is actually an integer :
try
{
int.Parse (this.textBox1.Text);
}
catch (FormatException fex)
{
...CODE to catch the exception
}
The code works but when the first exception occours, I observe a massive delay of two seconds or more. I guess that is the time when the DLL for the Exception is loaded. Once that has happened, there is no observable delay.
I observed the same for example when using data components (e.g. DataGrid) for displaying data. The first loading takes much longer than the consecutive ones.
Is there a way to load the according DLLs when the application starts ?
Thanks
ch
|
|
|
|
|
You can see if assembly loading is eating up your time by looking at the ".NET CLR Loading" performance object in performance monitor. This will tell you how many assemblies are loading and when. Make sure you look at your application process rather then the _total instance because it can be misleading. It is also a good idea to look at memory, exceptions and jiting in this case to see what is going on.
If the problem really is loading exceptions, which anything thrown by int.parse should be already loaded, then you should look into using ngen on your application to reduce startup time.
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
|
|
|
|
|
I have the same problem here, but only while running under the VS.NET debugger. When running standalone, the exception is very fast.
|
|
|
|