|
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.
|
|
|
|
|
Hi there,
I solved the problem now. Actually, the problem is that the code is translated into machine language in time. So, when first time executed, it takes a lot longer than subsequent calls. But, with the ngen.exe deployed with VS you can create a native image of your code and place it in the assembly cache, so that even the first execution is as fast as all the others.
regards
ch
|
|
|
|
|
I wanna ask easier way for an T-SQL Clause
Imagine a table AS following
CODE - TYPE - TOTAL<br />
1132 IN 100<br />
1134 IN 140<br />
1134 OUT 230<br />
1135 IN 240<br />
1135 OUT 50<br />
1136 IN 70<br />
1137 OUT 110
I need a sqlclause it will group by code and calculate Total, u have to multply OUT type with -1
the final table what i need to get is
CODE - TOTAL<br />
1132 100<br />
1134 -90<br />
1135 190<br />
1136 70<br />
1137 -110
I assume The clause like that
select CODE,SUM(If (TYPE='OUT',TOTAL*-1, TOTAL) from DETAILS<br />
group by CODE,TYPE Order by CODE
But something is missing
-- modified at 9:24 Monday 5th September, 2005
|
|
|
|
|
I think this is what you want.
select CODE, SUM(CASE WHEN (TYPE = 'OUT') THEN TOTAL*-1 ELSE TOTAL END )
from DETAILS
group by CODE
Order by CODE
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 please need to know how to round and format numbers in C#. For example how to round a number to 3 decimal places, and to format it with commas in, and to add the Rand sign, etc.
Regards,
Brendan
|
|
|
|
|
Look at the Math.Round(double, digits) method, the Double.ToString(format) method, and the String.Format(format, ...) method.
Examples:
double n = 3.1415926536;
double d = Math.Round(n, 3);
string s = n.ToString("0.###");
string s = n.ToString("c2", new CultureInfo(1053))
int i = 42;
string s = String.Format("Code: {0:00000}.", i);
---
b { font-weight: normal; }
|
|
|
|
|
Hi
Please help me in Overlapping the images
I have taken two images in two pictureboxes, the images (.bmp) type Polygon shapes. If i place one image on another the backgroud image is not displaying. how can i see the two images at the same time.
dhanunjay
|
|
|
|
|
I took an image in the piture box. i hav written the code for rotation using the Matrix. It is rotating. but if i stretch the image, image is not streching only picture box is stretching.Please help me to resize the image
|
|
|
|
|
Hello!
You can use the Property "SizeMode" in the PictureBox Class.
But you have to use the "Image" Property, not the "BackgroundImage".
_picturebox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
Good luck!
Martin
|
|
|
|
|
Hi,
how load to picturebox TIFF image with included color schema?
Greetings
|
|
|
|
|
Hi, I have the situation where I need to create a wrapper for an unmanaged dll. My only problem is that all examples are shown with the dll specified before hand. I would like to specify the dll to use at runtime. If this is possible, please let me know. My reason for this is I have about 10 dll's which are would all have the same signatures, but are designed to access differenct machines.
So basically if I am not able to pass in the dll to use when needed, I am going to be stuck having 10 different classes all to do a similar thing. Thanks
|
|
|
|
|
Hi, just to add a bit more to this, the following code would work fine, except that I have to mark dllLocation as const. If I change it, it does not work, and this is exactly what I need. So any help would be appreciated.
const string dllLocation = "test.dll";
[DllImportAttribute(dllLocation)]
public static extern void SetServerName (string pServerName);
|
|
|
|
|
Hi!
At least the name of the DLL has to be constant, if you use this approach.
If the path of the dll is unknown at compile time, then you can still change the current directory to the DLL's path at runtime and then use the DLL function, this will work.
Regards,
mav
|
|
|
|
|
Hi, its never known at runtime what the path will be. You mentioned though 'using this approach'. Could you let me know some other approaches I could use if this one does not help me?
|
|
|
|
|
If everything else fails you can P/invoke LoadLibrary and then try to call the functions in the DLL somehow. I think I saw an article here somewhere doing just this, but I could be wrong.
Good luck,
mav
|
|
|
|
|
I don't think it's possible to do it dynamically using .NET.
What you could do is make an unmanaged DLL that works as a stub, which is always the same. Then you link to that stub DLL from your .NET code. That DLL determines the path of the DLL to load, and uses LoadLibrary and GetProcAddress to link to 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
|
|
|
|
|
I have an array declared like this:
byte[,] grayPixels = new byte[rows, cols];
later in the code, (where I don't have access to rows or cols ), I have to iterate through grayPixels , I am using the following code to find the number of rows
int nRows = grayPixels.Length;
How can I find out the number of columns in the above array? Thanks in advance...
- A programmer's national anthem; "AAAAAHHHHH!!!!"
|
|
|
|