|
Well, need I say that if you're having trouble positioning the form, writing it may be an issue, too ?
You show the form relative to the button, work out how you want it to show relative to the button, and set it's position from the button location.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thats what my problem is.I Set the button's left as form's left and button's top+buttons'height as form's top.
This is the logic.
protected override void OnClick(EventArgs e)
{
SetAutoLocation();
frmCal.Show();
Invalidate();
}
private void SetAutoLocation()
{
Rect rect;
GetWindowRect(this.Handle, out rect);
Point tergatePoint;
tergatePoint = new Point(rect.left, rect.top + this.Height);
tergatePoint = new Point(Left, Top + Height);
if (rect.left + this.Width - frmCal.Width < 0)
{
tergatePoint.X = 0;
}
else
{
tergatePoint.X = rect.left - frmCal.Width + this.Width;
}
if (tergatePoint.X + frmCal.Width > System.Windows.Forms.SystemInformation.WorkingArea.Right)
{
tergatePoint.X = System.Windows.Forms.SystemInformation.WorkingArea.Right - frmCal.Width;
}
else if (tergatePoint.X < 0)
tergatePoint.X = 0;
if (tergatePoint.Y + frmCal.Height > System.Windows.Forms.SystemInformation.WorkingArea.Bottom)
{
tergatePoint.Y = rect.top - frmCal.Height;
}
if (tergatePoint.Y < 0)
{
tergatePoint.Y = 0;
}
if (tergatePoint.X < 0)
{
tergatePoint.X = 0;
}
frmCal.Location = tergatePoint;
}
public struct Rect
{
internal int left, top, right, bottom;
}
First click form is not positioning well ,but from second click onwards it is working fine.
Can you just see that logic is correct or not?
M.Sendilkumar
|
|
|
|
|
hi,
I am using datagridview in my project and i have 4 columns...
in one of the column i want to validate the data entry.
like in MaskedTextBox i want the column to be like xxx.xxx.xxx.xxx
user only should enter the values....
like settting the Mask property in MaskedTextBox..
Pls help me
With Regards
prasad
|
|
|
|
|
Maybe DataGridView.EditingControl Property would help. Set it to a MaskedTextBox and make the mask you want.
Regards
|
|
|
|
|
Hello everyone,
I was wondering if it is possible to change the light blue strip on the left hand side of the ContextMenu into a customized image.
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
If you want an image to be shown on the blue margin of the ContextMenu , Choose one of the items -usually the middle one-, then set the Image property of that item to the image you want. If you wan the image only next to that item this ould do it. If you want the image to spread all over the margin, set the ImageScaling property to false .
Regards
|
|
|
|
|
I am trying to construct a record in my database that has a Guid as the key. But I cannot find anything on actually generating a GUID. I'm surprised the Create is completely left out of the framework.
Any help would be appreciated.
Thanks.
|
|
|
|
|
theRealCondor wrote: But I cannot find anything on actually generating a GUID
Did you try Guid.NewGuid() method?
Regards
|
|
|
|
|
Hi,
I am doing a converstion from byte[] to hex string
byte[] aGroup = new byte[1024];
aGroup[] = {0,1,1,0,0,0,0,0,0,0,1,0,0...}
hexString = ToString(aGroup);
This is my To string function
public static string ToString(byte[] bytes)
{
string hexString = "";
try
{
StringBuilder temp = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
temp.Append(bytes[i].ToString("X2"));
}
hexString = temp.ToString();
}
catch (Exception)
{
}
return hexString;
}
After convertion my hexstring looks like this
000101000000000000010...00
where as it should be
0x06020
Is it that i need to do the conversion to base 16 first? any samples appreciated.
|
|
|
|
|
As I have shown you before, when your byte array only contains the values zero and one,
then the string will contain only the characters 0 and 1.
To convert bits into a hex string you somewhere somehow must pack 8 bits into one byte
(or 4 bits into one hex char); one way to do this is by using index/8 and 1<<(index%8)
|
|
|
|
|
I did stick the index/8 and 1<<(index%8) in the right place.
Thanks alot for the response.
|
|
|
|
|
The conversion is taking place as it should. Here's where I think you're tripping up:
aGroup[] = {0,1,1,0,0,0,0,0,0,0,1,0,0...}
Do you mean for this array to represent a binary value?
When a value of 0 is converted to hex, it is 0. A value of 1 is converted to 1 in hex. So the results of converting the above byte array to hex is not going to look any different than simply printing out the individual values of the array.
What you probably want to do is pack the binary values into the bytes, then do a conversion to hex.
Also:
aGroup[] = {0,1,1,0,0,0,0,0,0,0,1,0,0...}
hexString = ToString(aGroup);
I'm not sure what you're trying to accomplish here, but doing a ToString on an array is just going to give you something like, "System.Byte[]".
|
|
|
|
|
BitArray bitArray = new BitArray(aGroup.Length);
for (int i = 0; i < aGroup.Length; i++)
{
bitArray[i] = Convert.ToBoolean(aGroup[(aGroup.Length - 1) - i]);
}
byte[] hexValue = new byte[aGroup.Length / 8];
bitArray.CopyTo(hexValue, 0);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("0x");
for (int i = 0; i < hexValue.Length; i++)
{
stringBuilder.Append(hexValue[(hexValue.Length - 1) - i].ToString("X2"));
}
Console.WriteLine(stringBuilder.ToString());
|
|
|
|
|
Yes, because bit order is like this (8, 4, 2, 1)
That's why, if you have :
0110 = 8x0 + 4x1 + 2x1 + 1x0 = 0x6
0010 = 8x0 + 4x0 + 2x1 + 1x0 = 0x2 (and not 0x4)
|
|
|
|
|
Hello,
I've been puzzling over this all night.
I'm using the FileSystemWatcher(FSW) to monitor a folder and when a file is created within tis folder the FSW has an event handler which writes to a file thus logging the creation.
I want to use a Timer which will start within this event handler so that i can allow a set amount of time before doing my next task. To achieve this i tried declaring(and initalizing) the Timer within this event handler.
The problem is... if the event (creation of file) goes off more that once within the Timer's interval then I get mulitple Timers being created before the first timer has "gone-off".
Is there a way i can pass the Timer to the event handler so that i can Stop() it and then re- Start() it? Every time the creation event fires?
Or am i going about this the wrong way?
Thanks for any suggestions
|
|
|
|
|
Where is your FileSystemWatcher object? I assume it's in a class you've written, correct?
Create a timer object as a field to this class. In your method that handles events from the FileSystemWatcher object, check to see if the timer is running. If not, you're receiving the event for the very first time: Start the timer. Else the timer is running. Stop the timer, do whatever you need to do, and restart it.
My impression is that your creating the timer in the event handler. You thus lose the reference to it after the handler completes. By making the timer a field of the class, it's accessible within the class for the lifetime of the instances of the class (objects). Make sense?
|
|
|
|
|
Yes indeed you are correct. The Timer is being creates in the Eventhandler. How do i create it as a field to this class? I knew that this was the problem but i don't see a way of checking if the timer is already running.
|
|
|
|
|
Ylno wrote: How do i create it as a field to this class?
There are several timers[^] to choose from in the .NET Framework. First, you'll need to choose which one is appropriate. If you're using a form, the System.Windows.Forms.Timer[^] may do the trick. You can just drop it onto your form in the designer or manually add it yourself to your class:
public class MyClass
{
private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
}
To keep track of whether the timer is running, just check the timer's Enabled property:
public class MyClass
{
private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
private void HandleSomeEvent(object sender, EventArgs e)
{
if(timer.Enabled)
{
timer.Enabled = false;
}
else
{
timer.Enabled = true;
}
}
}
|
|
|
|
|
When I use the Invalidate() method in my form in the OnPaint() method, all my form does it start flashing like crazy. All I need for the form to do is refresh itself.
-----
Note: *** Never give me an answer have anything to do with Visual Studio. I don't have this program, and it'll be that way for a long, long time. ***
|
|
|
|
|
Invalidate() forces a paint event. Which calls onPaint. Which, in your code, calls Invalidate.
You have no need to call invalidate in your paint event, the form is already invalidated, hence the fact that your paint code is running.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I need the OnPaint event to call repeatedely, over and over. That's why I put Invalidate() at the end of the OnPaint event. Is there another way to do this without the screen flashing?
-----
Note: *** Never give me an answer have anything to do with Visual Studio. I don't have this program, and it'll be that way for a long, long time. ***
|
|
|
|
|
max29297 wrote: I need the OnPaint event to call repeatedely, over and over. That's why I put Invalidate() at the end of the OnPaint event. Is there another way to do this without the screen flashing?
Use a timer event to periodically invalidate the form. If you can call the overloaded version of Invalidate that takes a Rectangle to invalidate only the portion of the form that needs repainting, you'll get more efficient results. Invalidate() causes the entire surface of the form to be repainted.
|
|
|
|
|
What is an example of a timer event?
-----
Note: *** Never give me an answer have anything to do with Visual Studio. I don't have this program, and it'll be that way for a long, long time. ***
|
|
|
|
|
max29297 wrote: What is an example of a timer event?
For a form, you could create a System.Windows.Forms.Timer[^] object. Hook up to its Tick event, set the Interval property to the desired polling time, start the timer, and finally in response to the Tick events, invalidate whatever portion of the form that needs to be repainted.
|
|
|
|
|
Thank you!
-----
Note: *** Never give me an answer have anything to do with Visual Studio. I don't have this program, and it'll be that way for a long, long time. ***
|
|
|
|