|
I have seen several helpful examples of how to call API functions but I am confused about translating the data types. For example, I have seen DWORD parameters translated to both int and uint in c#. I am using a function that has a char[] parameter which I think should be translated as sbyte, but I'm just not sure. Any direction on a good reference for this?
Tym!
|
|
|
|
|
Try this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cscon/html/vclrfcomparisonbetweenccsharp.asp
Glenn
|
|
|
|
|
|
I have a richtext control, is there a way to count number of words or do I make my own function?
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
This will work assuming only one space is between each word:
this.richTextBox1.Text.Trim().Split(" ".ToCharArray()).Length;
|
|
|
|
|
Is there any way of obtaining the height of a main menu (menubar) or is it always the same size regardless of the screen resolution (i think its 20 pixels).
The reason why i need to know the height is that i'm trying to make a form with a picturebox inside a panel and resize the form so that it can view the whole image (assuming that my screen res is larger than the image). So i need to do some calculations and stuff..
|
|
|
|
|
Assuming you aren't using owner drawn menus the menu height is given by System.Windows.Forms.SystemInformation.MenuHeight .
James
"then when you go to bed...wait, you dont do that do you....ok....when you plug into the 'hive mind' to charge yourself, ill hack into your head"
Nnamdi Onyeyiri over MSN
|
|
|
|
|
Thanks. That did the trick.
|
|
|
|
|
I'm trying to call the Win32 SDK function CreateCompatibleDC in my application, I declared the function like this:
[DllImport("gdi32.dll")]
protected static extern IntPtr CreateCompatibleDC(IntPtr hDC);
but whenever i call it (with the hDC as IntPtr.Zero) it fails. When I check the error using the GetLastError function it is error 8, not enough memory. Why would this happen, I have plenty of RAM? Is there something i'm doing wrong?
Any help would be greatly appriciated,
thanks in advance,
dave
Dave Kerr
focus_business@hotmail.com
http://www.codechamber.com
|
|
|
|
|
Try the following:
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
public static extern IntPtr CreateCompatibleDC(IntPtr HDC);
[DllImport("gdi32.dll")]
IntPtr ScreenDC = GetDC(IntPtr.Zero);
IntPtr NewDC = CreateCompatibleDC(ScreenDC);
HTH
-Nick Parker
|
|
|
|
|
Hi nick,
i tried what you suggested but I still have the same problem, i'm getting *something* back from the CreateCompatibleDC call, but when i check for errors, it still gives error 8. Then I create a DIB Section using CreateDIBSection from the HDC (and other data) and try and call SetPixelFormat on it, and SetPixelFormat never ever works, it always gives error '1'. Its to create an OpenGL compatible DIB Section, and i just cant do it!
Any ideas?
Cheers,
dave
Dave Kerr
focus_business@hotmail.com
http://www.codechamber.com
|
|
|
|
|
Try changing the DllImport so that the SetLastError field is set to true.
[DllImport("gdi32.dll", SetLastError=true)] , this tells the marhsaller to call GetLastError for you. You can then get the error code by calling DllImportAttribute.GetLastWin32Error() . It may not make any major changes, but it ensures that another Win32 call won't change the value, especially if that call is made by the framework.
James
"then when you go to bed...wait, you dont do that do you....ok....when you plug into the 'hive mind' to charge yourself, ill hack into your head"
Nnamdi Onyeyiri over MSN
|
|
|
|
|
I've an xxx.aspx page which has couple buttons. Based on button click I'm loading ascx files using
Case 1
Page.LoadControl("xxx.ascx")
Case 2
Page.LoadControl("yyy.ascx")
...
...
In my xxx.ascx and yyy.ascx files, I've a grid control which I want to populate using "BindGrid()" method only
if (!Page.IsPostBack)
But it appears to me when I use "if (!Page.IsPostBack)", the binding doesn't happen and if I remove it it works fine. In simple words, looks like there's no PostBack when it comes to LoadControl.
I want to use "if (!Page.IsPostBack)" because for everything I'm doing with grid calls the PageLoad eachtime like if I click on "Next Page" (i've paging enabled for the grid), it calls PageLoad and same PageLoad is called when "Prev Page" is clicked.
Somehow I want the ascx PageLoad to appear once rather than each time.
Any Suggestions? Comments?
I really need some help.
|
|
|
|
|
Jay Pal wrote:
Any Suggestions? Comments?
You may get more help with this on the ASP.NET[^] forum, however I have a feeling that because you are dynamically loading controls they can't identify the state of your page, they are just being loaded themselves so they wouldn't know what happened before (internally to the control that is). HTH
-Nick Parker
|
|
|
|
|
This is starting to get to me !
So, let me ask you all, just in case someone has a quick solution for my problem.
Here's what I would like to do.
Imageine a simple Win App, with a main form with a couple of buttons,
and a panel. The buttons are "Rectangle", "Ellipses", and "None".
If you click on the "Rectangle" button, you can draw a rectangle in
the panel (by clicking-dragging in the panel). Similarly,
if you click on the "Ellipses" button, you'll be able to draw an ellipses in the
panel. The "None" button is there simply to let you go back to
your standard mouse situation.
So far so good.
I got all of that working by using the GDI+ DrawRectangle and
DrawEllipses functions.
Now, my problem is that I can't make the panel pop-up the scrollbars
(both vertical and horizontal) as needed.
In other words, if I open up the application,
maximize it to full screen, and draw something in the lower-right corner of the
panel, when I resize the application to a smaller size,
the drawn object does not show up in the panel (duh! it's out there somewhere).
But, most importantly, the scrollbars of the panel do not appear either !
I've tried to set to true the AutoScroll property of the panel,
and set the minimum size and the actual size of the scrollbars to (5,5),
but that had no impact.
As far as I can tell, the problem is that the AutoScroll property comes
into play only if some "Control" is placed outside the viewable
area of the panel at some point, while the rectangles and circles are
(being drawn with GDI+) not considered controls !
Any suggestions ?
Thanks in advance for your 2 pennies
F.O.R.
|
|
|
|
|
Got it !
Just for future reference of anyone who stumbles upon this:
look at the following two articles here on CodeProject:
http://www.codeproject.net/books/1861004990.asp
and
http://www.codeproject.com/cs/miscctrl/tracker.asp
As a summary, I think my main mistake was to set the
AutoScrollMinSIze to a value that was too small (5,5).
Once I set this to the value of the highest X (and Y) coordinate
of the stuff I was drawing, it worked much better!
HTH,
F.O.R.
PS: funny thing is I *do* have the WROX book from the first link,
but I left it at the office !
|
|
|
|
|
I'm pretty new to C#. Could someone give me a short step-by-step description on how to embed an ActiveX control (made with ATL) into C#? Is it possible at all?
Thanks in advance,
Robert
|
|
|
|
|
Wright Click on your Refrences and then choose COM tab,choose your active x there.
Mazy
No sig. available now.
|
|
|
|
|
Is it possible to create an control that has for example a property which has a (self created) property building screen. In this screen you can set the contains of this property. After closing this screen, this screen will generate some code in te code-behind file.
I was hoping someone could tell me if this is possible. With add-ins it could but i want a sexier way. If this is not possible, than can someone tell me if i can make a add-in which will look like the property window in VS.Net?
|
|
|
|
|
Can you help me with a good, from ground up, with pictures and links tutorial - how I can edit HTML document from inside C# ? I readed MSDN articles about MSHTML editing but I'm still have some questions
"I have not failed.
I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
|
|
|
|
|
|
10x man !! But I already found the answer.
Some sites to look for:
http://abstractvb.com/code.asp?P=1&F=51 [VB site]
Google.com [try to search for every interface name you found or question about - it's really helps]
"I have not failed.
I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
|
|
|
|
|
This is probably a basic question to one who has the answer, but I can't seem to find the forest for the trees.
I put together the main form (frmMain) and I have several user controls that I put together. Silly me, I only tested the process on a single form before moving forward.
I created the main form with a panel (pnlMain) into which I paste my user control (UC). When the user clicks on a button, my intention was to call a public routine in frmMain that would 1) Hide the current UC and then load and paste an appropriate new UC into the panel.
The problem is hierarchy. No matter how I put the controls together, once the child form is open, I can't get back to the main form to tell it to do something different. I've tried a few different variations but I keep running into the hierarchy issue no matter the method of object creation.
I've done this type of thing in Delphi but can't seem to figure out the C# secret.
Thanks for the help.
DBetting
|
|
|
|
|
I not sure I understand your issue. Seems to me there should be many ways to get back to your main from.
Anyway, try this;
Form frmMainRef = (frmMain)this.Parent();
//frmMainRef is a reference to the parent. If you are nested deaply you may need to put this into a loop until ype of frmMainRef is form.
Something like this...
Form frmMainRef = (frmMain)this.Parent();
while(frmMainRef != null && frmMainRef.GetType() == typeof(Form)
{
frmMainRef = (frmMain)this.Parent();
}
good luck, let me know
|
|
|
|
|
For a simple test of visibility and the concept: Given a main form (frmMain) with a panel (pnlMain), using the following:
public class frmMain : System.Windows.Forms.Form<br />
{<br />
...<br />
public ucForm1 UCForm1 = new ucForm1();<br />
public ucForm2 UCForm2 = new ucForm2();<br />
... <br />
public frmMain()<br />
{<br />
InitializeComponent();<br />
UCForm1.Parent = this.pnlMain;<br />
UCForm1.Visible = true;<br />
}<br />
<br />
public void ShowUCForm2()<br />
{<br />
UCForm1.Visible = false;<br />
UCForm1.Parent = null;<br />
UCForm2.Parent = this.pnlMain;<br />
UCForm2.Visible = true;<br />
}<br />
}
then given a User Control with a single button (btnViewOtherForm) using the following:
public class ucForm1 : System.Windows.Forms.UserControl<br />
{<br />
...<br />
private void btnViewOtherForm_Click(object sender, System.EventArgs e)<br />
{ <br />
Form frmParent = (frmMain) this.Parent;<br />
frmParent.ShowUCForm1();<br />
}<br />
}
ucForm2 can be blank. I tried the suggestion, but the reference to ShowUCForm2 cannot be found. I cannot use the loop because the compiler wants to find the reference before it allows it to be used. I've tried several flavors of trying to access the parent, but obviously not the correct one yet.
In this case, the parent should be two levels up. ucForm1.Parent should be pnlMain whose parent should be frmMain.
Thanks
Dan
|
|
|
|