|
Be careful with code like this:
Paul Silvernail wrote:
private void Form1_Load(object sender, System.EventArgs e)
{
image1 = new Bitmap(GetType(),"icon1.png");
image2 = new Bitmap(GetType(),"icon2.png");
SelectionCursor = new Cursor(GetType(),"Cursor1.cur");
this.pictureBox1.BackgroundImage = image1;
}
If you create a new form which inherits from Form1 , but doesn't exist in the same namespace or assembly; the constructors will throw an exception because the resource can't be found. GetType() will return a Type object for the new form, not for Form1 resulting in the exception.
A better way to do it is to use typeof(Form1) so that you will always be referencing the correct Type object.
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
|
|
|
|
|
Hi,
I'm trying to add in an ImageList >3000 icons. It takes a lot of time. How can I do it work faster ? This ImageList will be used for viewing in Listview.
Thanks in advance
|
|
|
|
|
You wanna use a technic called using an imagestrip. The is some docs on MSDN how to do this, but basically you create a single really long image and load that into the imagelist. The rest is taken care off AFAIK.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Hi,
Sorry about putting this in the ASP.NET forum as well...
I've been developing an ASP.NET website for quite some time. The site is located on a w2k server and I have been using remote debugging, which was working quite fine. Took some time to get there though... but it worked just as it should.
Then suddenly, I cannot debug anymore ! I open VS (2003 btw.), open the project and press CTRL-F5 - the site opens in a browser and works fine. But if I press F5 instead, VS opens misc. debug windows (locals, call stack etc), writes "Run" in the caption - but no browser window shows up. Followingly, VS is locked up - it just doesn't respond. Then I can open a browser window manually and go to a page I know I have a breakpoint in, and VS will break at that point - however, still locked up. After that, all I can do is terminate the asp worker thread on the server and kill the VS process on the client. Very strange...
Anybody who has any ideas at all ? I've tried with different startup pages - but with the same result.
Thanks in advance.
Jan Hansen
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
|
|
|
|
|
|
I'm trying to develop a custom component library in C#. One of the set of objects in these components would be dropdown controls (DateTime picker with dropdown calender, Numeric edit with dropdown calculator, dropdown tree control, etc.)
From what I understand, for these objects (calendar, calculator, tree, etc.) to drop down in the "correct" way, they shouldn't be forms, but actually WS_POPUP windows that have the desktop as their parents. I'm imagining they should capture the mouse as soon as they drop down, report to their owner (textbox, or whatever dropped them down) and then release the mouse. Am I missing something? Is this the correct approach?
Problem number two. Is the following methodology right: I should define an interface (IPopupControl) and implement it with every desendant (like for instance: DropDownTreeView: TreeView, IPopupControl). The reason is then I should be able to assign any dropdown control to an owner, and then the owner would always call a method (like IPopupControl.Popup) because it will always be implemented. So in other words, the owner will always be accepting one object [object?] which is IPopupControl instead of a specific object (DropDownXXXX) according to what it wants to drop down. Then of course, every dropdown control will implement its own methods that are different, to report the data back to the owner control (most probably textbox).
I would have to call some Windows APIs in this process I would imagine. What are the disadvantages?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
profoundwhispers wrote:
From what I understand, for these objects (calendar, calculator, tree, etc.) to drop down in the "correct" way, they shouldn't be forms, but actually WS_POPUP windows that have the desktop as their parents. I'm imagining they should capture the mouse as soon as they drop down, report to their owner (textbox, or whatever dropped them down) and then release the mouse. Am I missing something? Is this the correct approach?
Forms are fine. You just have to set their style bits correctly.
WS_POPUP is out! You might think it should be used (as I once did), but when the WS_POPUP style is set, it causes the parent form's title bar to be "inactive" when the popup has focus. This would cause the user to be confused.
So here's the code to set the style bits:
int nStyle = GetWindowLong(this.Handle, GWL_STYLE); nStyle^=Win.User.WS_POPUP;
nStyle^=Win.User.WS_POPUPWINDOW;
SetWindowLong(Handle,GWL_STYLE,nStyle);
int nExStyle = GetWindowLong(this.Handle, GWL_EXSTYLE);
nExStyle|=WS_EX_PALETTEWINDOW;
SetWindowLong(Handle,GWL_EXSTYLE,nExStyle);
profoundwhispers wrote:
Problem number two. Is the following methodology right: I should define an interface (IPopupControl) and implement it with every desendant (like for instance: DropDownTreeView: TreeView, IPopupControl). The reason is then I should be able to assign any dropdown control to an owner, and then the owner would always call a method (like IPopupControl.Popup) because it will always be implemented. So in other words, the owner will always be accepting one object [object?] which is IPopupControl instead of a specific object (DropDownXXXX) according to what it wants to drop down. Then of course, every dropdown control will implement its own methods that are different, to report the data back to the owner control (most probably textbox).
That would be one way to do it, but then you would have to re-implement the basic popup code for each of them. Why not have a Popup class that they all derive from?
profoundwhispers wrote:
I would have to call some Windows APIs in this process I would imagine. What are the disadvantages?
Not any that I know of...
Ok, as far as closing the popup, here's how I do it:
With menus and combo dropdowns, you grab the mouse capture with SetCapture() when the mouse is outside your menu, and release the capture with ReleaseCapture() when the mouse is inside your menu (so that any contained controls can get mouse messages). Close the popup when a MouseUp event is recieved and the mouse coordinates are outside of the form's bounds. You will also want to close the popup when it recieves a WM_APPACTIVATE message where the app being activated is not your own.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
This is a quick fish for thoughts. I do know and am intending to do an article on how circular references to dll's can mess things up in when using csharp but for know I have this problem which is not a circular reference but may well get included in the article if anyone can come up with anything useful here
the problem is this.
I have a library dll say Libdll and a main project say mainexe and another dll that uses the library dll say libdll2.
When I compile the project the libdll2 project is compiled first and copies the libdll to the project output folder. Then when the mainexe compiles it complains that it can't copy the libdll to the output folder as this will overwrite the copy already there. ( even though it is the same library version ) This in effect means that the mainexe is unable to debug any code in the libdll.
Note that the main project is a test bed for building the libdll in the first place so the code is constantly changing and in need of debugging.
Any thoughts, answers?
pseudonym67
Neural Dot Net Articles 1-11 Start Here
Fuzzy Dot Net Articles 1-4 Start Here
"Do you hide in Happy Hour?" Marillion Clutching At Straws
|
|
|
|
|
I've had this problem before. I don't know WHY it surfaced... It seems that a process has hold of the libdll file, so it can't be overwritten.
When I see this problem, I close down VS.net, remove libdll from the folder that mainexe is compiled into.
When I startup VS.net and open the project again, I don't see this problem again.
|
|
|
|
|
Sounds like a very similar problem we just had yesterday. We had one session running to modify the dll library. The second session was running the main program that referenced the dll library. Every time a change was made to the library, the debugger would no longer work on the dll library code. We tried several things and after being frustrated with shutting down the code several times, we found the following solution.
Solution: Make the appropriate change to the library code and build the source. Go to the main application, remove the reference to the dll and then re-add it. It takes about 10 seconds to do, it is tedious, it is senseless that it has to be done, but it worked! We were successful in completing the debugging in a reasonable time.
db
|
|
|
|
|
Hi Everyone -
I am trying to create a C# wrapper around a legacy C .DLL
I am stuck on one implementation area...
There is a DLL function called GetDateTime
extern "C" bool GetDateTime( DateTimeStruct &dateTime )
is how the SDK says it is to be implementated.
I have created a wrapper shell for this function below...
[DllImport("CarChipSDK", EntryPoint="GetDateTime")]
public static extern bool GetDateTime
(
//// what goes here???
);
I have create the struc in BOTH the main program,
and the shell
[StructLayout(LayoutKind.Sequential)]
public struct DateTimeStruct
{
public int year;
public int month;
public int day;
public int hour;
public int minute;
public int second;
}
Here are the questions...
1) Do I need to create a struct in both the caller and callee classes?
2) How do i setup the caller class to send the struct to the callee class?
thanks
tony
|
|
|
|
|
I haven't done this before, but have been researching for my own project. This is how I think it should work...
define the struct in your "callee" class namespace:
<br />
namespace myNS<br />
{<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct DateTimeStruct{...}<br />
<br />
class Callee{<br />
[DllImport("CarChipSDK", EntryPoint="GetDateTime")]<br />
public static extern bool GetDateTime <br />
(out DateTimeStruct dateTime);<br />
}<br />
}<br />
in "Caller" add MyNS as reference, add new DateTimeStruct variable and then call your function, passing this variable by reference:
<br />
using MyNS;<br />
...<br />
DateTimeStruct dts;<br />
...<br />
Callee.GetDateTime(out dts);<br />
...<br />
int hr = dts.hour;<br />
Let me know if this works.
Tym!
|
|
|
|
|
I don't why I'm getting this exection. No idea what does
this mean.
Here is the code :
In this CollectionFactory is for creating a new instance
for VBA collection because we cannot use new on VBA
collection outside VB.
CollectionFactory.clsVBACollectionClass Col = new CollectionFactory.clsVBACollectionClass();
VBA.CollectionClass mHoliDates = (VBA.CollectionClass) Col.CreateVBACollection();
System.Collections.IEnumerator e = oAdsCollection.GetEnumerator();
while( e.MoveNext() != false )
{
IADSObject oAdsObject = (IADSObject)e.Current;
DateTime dt = (DateTime) oAdsObject.GetValueByIndex(0);
object oValue = (object) oAdsObject.GetValueByIndex(0);
object oKey = (object) dt.ToString("mm/dd/yyyy");
mHoliDates.Add(ref oValue, ref oKey,ref oMissing,ref oMissing);
}
if I'm commenting following line in code above then I'm
not getting any exception
mHoliDates.Add(ref oValue, ref oKey,ref oMissing,ref
oMissing);
mHoliDates is a VBA.Collection.
oAdsCollection is COM collection written in MS VC++
And I'm getting exception on this line
while( e.MoveNext() != false )
|
|
|
|
|
One cannot modify a collection while enumerating thru it. You will have to look for another solution.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
But I'm not enumerating thru same collection. I'm enumerating thru oAdsCollection which a c++ com collection and trying to modify VBA Collection mHoliDates.
I'm getting exception on while( e.MoveNext() != false ).
|
|
|
|
|
Sorry I miss read that a bit, I think you will need to copy your references perhaps.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
As leppie says, you can't modify a collection while enumerating through it. My suggestion is to add the items to a separate collection, and then add them all at once after you're out of the foreach loop.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I found the problem. My data was wrong I was adding duplicate Keys in my VB collection
|
|
|
|
|
|
|
|
1. In the code below I refine an array and add two properties to it. I can add elements to this array but can not read them back.
public class C_myList : System.Collections.ArrayList
{
public C_myList()
{
}
public void Add(string sString, int iNumber)
{
m_sString = sString;
m_iNumber = iNumber;
base.Add(this);
}
//refine the arraylist by adding two properties
public int m_iNumber;
public string m_sString;
}
2. Now I would like to add some items to this array and read them back. I can add them but what is the syntax for reading them back?
private void button1_Click(object sender, System.EventArgs e)
{
C_myList aList = new C_myList();
for(int i=0; i < 20; i++)
{
aList.Add(i.ToString(), i * 2 );
}
/*for(int x =0; x < 5; x++)
{
int ivalue = xList[x];
int ivalue2= xList[x].m_iMajorTabOrder;
}*/
}
thanks
|
|
|
|
|
are you sure your code is correct?
what is the intention of base.Add(this) ?
eperales
|
|
|
|
|
make life easy for yourself. store the information in a struct, then use ArrayList to store an array of structs.
To those who didn't make it, we will remember you. To those who did is back. - Megan Forbes in Black FridayAnother Post by NnamdiOnyeyiri
|
|
|
|
|
There is VSS in Visual Studio 6.0. But I can't find it in Visual Studio .Net
Anyone know why?
Thanks in advance.
|
|
|
|