|
Sunil G wrote: First of all sorry for what i have posted.
No problem!
Sunil G wrote: Exception is not occuring in my application. I have debugged my application, it never goes to catch block. But when below line of code get executed then only it gives an error (JIT dialog box). The function runs successfully. The function returns a non-zero value.
Right, I see! the problem is not in the app you are debugging - it is in "ServiceManager.exe" - you need to try running that outside your app with no parameters and see what happens - it is failing for some reason. It may be that it needs better permissions, it may need a DLL it can't find, it could be anything!
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
When I manually execute the exe it runs without any error.
what kind of permissions I have to set?
|
|
|
|
|
Sunil G wrote: what kind of permissions I have to set?
I don't know! Can't you just use Process.Start? Since you don't seem to be specifying a username you (presumably) are running as the current user. Or am I missing something?
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Hi Griff,
I admire you being persistent about PRE tags; maybe you should add one more sentence, something like "you could still edit your existing message and add PRE tags in; please do so".
Cheers.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, when do we get it on regular forums?]
|
|
|
|
|
Hi Luc,
The last time I did that, I got the same multipage listing, but in tags!
finally
{
if (pi.hProcess != IntPtr.Zero)
CloseHandle(pi.hProcess);
if (pi.hThread != IntPtr.Zero)
CloseHandle(pi.hThread);
if (hDupedToken != IntPtr.Zero)
CloseHandle(hDupedToken);
}
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
I have modified my previous post. Please check it.
Thanking You,
Sunil G.
|
|
|
|
|
I am attempting to populate a ContextMenuStrip (or any ToolStripDropDown for that matter) with ToolStripMenuItem s that have AutoSize set to False and a specific Height and Width . However, I cannot get the ContextMenuStrip to AutoSize (which is set to True on the ContextMenuStrip ). The Height appears to be resized, but the Width cuts off the menu items. I have tried using varying values for Margin , Padding , AutoSize , Width , Height ... etc... but to no avail. Any ideas?
private void AddMenuItem (ContextMenuStrip oContextMenuStrip, string sText)
{
oContextMenuStrip.AutoSize = true;
ToolStripMenuItem oMenuItem = new ToolStripMenuItem(sText);
oMenuItem.AutoSize = false;
oMenuItem.Width = 300;
oMenuItem.Height = 40;
oContextMenuStrip.Items.Add(oMenuItem);
}
|
|
|
|
|
You can adjust width by yourself, use Graphics.MeasureString to get the width of the menu item and set width manually.
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:52am.
|
|
|
|
|
Yes, I had tried that. However, it did not accomplish what I wanted to achieve. The menu item will be completely custom drawn, but there is some text that I'll need to assure will fit. So, I calculated the width of a space in the menu item font, measured that text that will be rendered to it (though text measuring in .NET is sometimes inaccurate), and set the menu item text to all spaces (see code below). However, every menu item in that drop down will have the same height now if there is more than one line. And, we have no way of making the menu item an exact dimension since we can only affect width/height using spaces and newlines in the menu item text. Ideally, I'd like to know if there is a clean way to resolve such drop-down menu and menu item dimension inconsistencies. Perhaps a "DoWhatIWant" flag?
private void AutoSizeCustomMenuItem(ToolStripMenuItem oMenuItem, string sText)
{
int iPreferredHeight = 50;
int iPreferredWidth = 0;
int iPadding = 50;
SizeF oSizeSpace = SizeF.Empty;
using (Graphics oGraphics = oMenuItem.Owner.CreateGraphics())
{
iPreferredWidth = (int)oGraphics.MeasureString(sText, oMenuItem.Font).Width + iPadding;
oSizeSpace = oGraphics.MeasureString(" ", oMenuItem.Font);
}
int iSpacesWidth = (int)Math.Ceiling((double)(iPreferredWidth / oSizeSpace.Width));
int iSpacesHeight = (int)Math.Ceiling((double)(iPreferredHeight / oSizeSpace.Height));
string sSpacesWidth = new String(' ', iSpacesWidth);
StringBuilder sbMenuItemText = new StringBuilder();
if (iSpacesHeight > 0)
{
string sLineDivider = String.Empty;
for (int i = 0; i < iSpacesHeight; i++)
{
sbMenuItemText.Append(sLineDivider);
sbMenuItemText.Append(sSpacesWidth);
sLineDivider = "\r\n";
}
}
oMenuItem.Text = sbMenuItemText.ToString();
}
|
|
|
|
|
hi
Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
// in this line of code:
ExcelApp.Application.Workbooks.Add(Type.Missing);
error:
Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
can any one help me ?
H.R
|
|
|
|
|
1. You can export datatable that you use to bind your datagridview through OleDb into Excel file. There won't be any need of interop.
2. Did you googled the error message?
3. What are trying to do in that line of code?
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Okay, I'm sure someone out there besides me has wondered this so here goes.
Lets say your like me and learning c# or your a professional either way. If your working on a project and lets say you get it all working then someone wants something different added or deleted. How do you go about editing the working code without risking screwing up the whole project?
What I mean is this. Lets say program1 had a button and you build the project and all works fine. Then later on you decide you don't want the button so you open up the project and remove it. If all crap breaks loose and it no longer runs how would you revert back to the old so you can try something different?
I have been taking and raring the project folder as a backup and then just working from there but is there a better way to do this ?
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:54am.
|
|
|
|
|
thanks. One last question before I call it quits for the night.
On the toolstrip one can have add delete save whatever.
Well if I remove the delete button how in the heck can i get it back or do I have to delete the toolstrip
and start over? Or is there an easy way to add an event that does the same thing as the delete?
Like databindingsource.delete(current) or whatever? Sorry for all the questions I'm just trying to understand this stuff.
|
|
|
|
|
If you use a source control solution you'll be able to "commit" your working code. If you then decide to remove the "delete" button and change your mind on that, you can simply put back the old code using you source control program and the button will be there again.
I have no idea what it is that you want to delete, but if you need to duplicate the function of your delete button you can just copy the code in the event handler for it's click event to the place you need it to be. If this concept is unclear you might want to pick up a book on c# as this is very very basic stuff.
Standards are great! Everybody should have one!
|
|
|
|
|
Source control is what you need. There are a number of free ones and even more that cost you. Just google for source control and you will find loads. This is how the vast majority of commercial development is controlled.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
I want save some information(gps data and coordinates and ...) in text file and then export this text file to .m file (for useing in matlab7.1).
|
|
|
|
|
Good, go ahead and do it. Or was there a question somewhere that I missed?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Howdy,
I'm working with an widget that is getting key strokes as (System.Windows.Forms) KeyEventArgs. In particular I'm currently working on controlling input from the numeric keypad on that widget.
When this widget gets input from the numeric keypad, I want to ignore whether or not caps lock is on and always enter a number: pressing numeric keypad 4 should enter a number 4 whether or not num lock is on.
I don't think I can just ignore the num lock status (although I'm open to suggestions), so I'm trying to come up with a way to work with the KeyEventArgs. I'd like to determine how I can map the KeyEventArg that the widget gets and send a number instead.
The problem is:
I can't find anyway to differentiate the numeric key pad 4 with num lock off (that sends a '<-') from the actual '<-' key input.
I also can't tell the difference between the numeric key pad 7 with num lock off (that sends 'home') from the 'home' key input.
Its obvious how I could go the other way and tell the difference between the numeric keypad 4 with num lock on (sending a 4 or more specifically a Keys.Num4) and the '4' key (that would send Keys.D4).
Is it possible to differentiate between control characters sent from the numeric key pad and the normal control keys? Is there another way I might get the effect I'm looking for?
(Hope that's readable, that whole key pad 4 with num lock off is a bit wordy, so ask me to clarify it if you can't follow).
Thanks,
Chris
modified on Monday, January 18, 2010 6:30 PM
|
|
|
|
|
AFAIK managed code will not help out; for the numeric keypad, all KeyEventArgs properties depend on NumLock, and when not locked the keys duplicate other keys.
So I expect you will need a lower-level solution and some P/Invoke. I don't have the details though.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, when do we get it on regular forums?]
|
|
|
|
|
Hi all, pardon me, I need helping at the following code. When I run this code to get the IP address (at statement Console.WriteLine(ipAddress)) I get the IP address, subnet mask and network family at this maner:
169.254.25.129
255.255.0.0
255.255.255.255
but I need to get each of them uniqly (each one alone of others), and I need to get these using this code of the programe (this code from SharpPcap.2-1-1)….
Regards…………………………..
public Sockaddr(IntPtr sockaddrPtr)
{
// A sockaddr struct. We use this to determine the address family
PcapUnmanagedStructures.sockaddr saddr;
// Marshal memory pointer into a struct
saddr = (PcapUnmanagedStructures.sockaddr)Marshal.PtrToStructure(sockaddrPtr,
typeof(PcapUnmanagedStructures.sockaddr));
// record the sa_family for informational purposes
_sa_family = saddr.sa_family;
byte[] addressBytes;
if(saddr.sa_family == Pcap.AF_INET)
{
type = Type.AF_INET_AF_INET6;
PcapUnmanagedStructures.sockaddr_in saddr_in =
(PcapUnmanagedStructures.sockaddr_in)Marshal.PtrToStructure(sockaddrPtr, typeof(PcapUnmanagedStructures.sockaddr_in));
ipAddress = new System.Net.IPAddress(saddr_in.sin_addr.s_addr);
Console.WriteLine(ipAddress);
}
}// end of Sockaddr function
/////////////////////////////////////////////////////////////////////////////////
// A PcapUnmanagedStructures class is here:
public class PcapUnmanagedStructures
{
#region Unmanaged Structs Implementation
[StructLayout(LayoutKind.Sequential)]
public struct sockaddr
{
public UInt16 sa_family; /* address family */
[MarshalAs(UnmanagedType.ByValArray, SizeConst=14)]
public byte[] sa_data; /* 14 bytes of protocol address */
};
/// <summary>
/// Structure that holds an ipv4 address
/// </summary>
public struct in_addr
{
public UInt32 s_addr/*= 1111*/;
}
/// <summary>
/// Structure that holds an ipv4 address
/// 'struct sockaddr'
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct sockaddr_in
{
public UInt16 sa_family; /* address family */
public UInt16 sa_port; /* port */
public in_addr sin_addr; /* address */
// TODO: would be great to be able to have the compiler take care of this for us
// but I'm not sure how to
// pad the size of sockaddr_in out to 16 bytes
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
private byte[] pad;
};
}// end of the PcapUnmanagedStructures class
|
|
|
|
|
|
Hey everyone!
This is my first question that I've asked on this forum. I'm a fairly experienced C# coder who has browsed this site but never posted anything.
My question is simple, fairly straight forward. I would like to be able to select an object I have drawn with the System.Drawing.Graphics class. I would like to know how I could process the drawn-on control's MouseDown event so that the program can detect which objects have been drawn
this.CreateGraphics().DrawLine(new Pen(Color.Blue) { Width = 2.5f }, new Point(0, 0), new Point(50, 150));
This kind of drawing. I don't want to create a new control for every object being drawn on the screen, unless of course there is some way of doing it that doesn't hamper performance.
I have 2 ideas, but they aren't efficient enough, especially with a managed language such as C#. It is as follows: the program stores the information of which points inside the control are painted on. For example, the software could know that there is a blue pixel at point (20; 40). If the MouseDown event has to process every point, than I would imagine this method is extremely inefficient. Also, working out the area of a completely irregularly shaped object would be possible, but not in this case considering there are going to be user-defined/created objects drawn on screen.
Any advice on how I should do this? Any advice would be very helpful. Code samples would be a huge help.
Thanks A Lot,
Genius Mchlahla, (Amateur South African Programmer)
|
|
|
|
|
Which out of the following are you doing? I can give you an answer for any of them...
- Hit-testing individual shapes - i.e. determining whether the mouse is over a shape, and if so, which one of the shapes on your control it is over.
- Hit-testing the entire control - i.e. determining whether the mouse is over any drawn object on the control
- Determining redraw or clipping areas
I'll assume the first one for now, so here's a fairly efficient way to hit-test to determine which individual shape, if any, the mouse (or any other single point) is over.
First, you need to set up code to create a GraphicsPath for the shape that matches what's being drawn. For example, a GraphicsPath for a set of circles could be created like this:
var gp = new GraphicsPath();
gp.AddEllipse(myCircleRect1);
gp.AddEllipse(myCircleRect2);
Now, you can call gp.IsVisible(pt) to determine if a given point is over any filled part (as opposed to the outline) of the shape if it is a filled shape, or gp.IsOutlineVisible(pt, pen) to determine if a point is within the outline of the shape if it is not filled. If you want to check both the outline and the inside of a shape at the same time, use gp.Widen(pen) when you create the graphics path, after adding the shapes. In either case, be sure that your pen has all the characteristics of the one being used to actually draw the shape - width, mitre mode, end caps, dash type, etc. The GraphicsPath hit testing methods take these into account, which saves you a huge amount of coding to determine the actual line's hit test area.
To make use of this efficiently, this is probably the best way:
1. Re-build the shape's graphics path when the shape and/or drawing pen changes. Use gp.GetBounds() to get the outer bounding rectangle of the graphics path. Make sure to either pass the pen to GetBounds(), or use gp.Widen() when creating it as I mentioned above. Store the bounds of the shape with the object itself. If you have a whole lot of shapes, don't keep the graphics path around - call Dispose() on it and get rid of it. If you have a smaller number of shapes, you might want to store the GraphicsPath along with the cached bounds.
2. When a mouse down event happens, search through your list of objects (sorted by z-order so that you check the topmost shapes first), and find the first bounding rectangle that contains the mouse cursor point. When you find one, either retrieve your stored graphics path or create a new one (as above), and use IsVisible() or IsOutlineVisible() as above to find out if the mouse is actually over the shape. If not, continue to check bounding rectangles until you find another one that the mouse is within, and test the graphics path on that one, etc.
If you store the graphics paths, sure to cache the bounding rectangle when an individual shape changes, instead of calling GetBounds() on each object each time the mouse is clicked. Otherwise you won't be saving some CPU expense that you could otherwise save. Also no matter what you do with the GraphicsPath objects (caching them or discarding them immediately), always call Dispose() when you're completely done with them, just like you do with Graphics, Pen, and Brush objects.
Also note that the bounding rectangle is good to do hit testing with, but if you're determining the drawn area for redraw purposes or for clipping, you'll need to widen the bounds by a pixel in each direction to account for the possibility of antialiasing effects that could be outside of the hit testing bounds.
|
|
|
|
|
Thank you! I've been trying to figure this out myself but to no avail... This code is helpful
|
|
|
|
|