I have a tab control which initially has one tab page. I want to dynamically create some more tab pages which should have the same controls as the first one.
To read the controls on the first page I am doing the following :
Control myObjArray = new Control[this.tabControl1.TabPages.Controls.Count];<br />
The problem is, when I try to add the controls obtained using the above method, the controls are removed from the first page.
Control NewControl = new Control();<br />
NewControl = (Control)myObjArray[nCount];<br />
This method however successfully puts the controls on the newly created page.
Any ideas how I can have the controls on both the pages ?
Control objects are reference types, and by they can only belong to one parent (typical in a window manager). You're not actually cloning these controls so they are getting re-parented in the new TabPage.
Perhaps a better - more object-oriented - approach would be to subclass TabPage and initialize all the controls in the constructor (like VS.NET does when you add controls to a Form, UserControl, etc.). Then you simply need to instantiate and add your custom TabPage class. New instances of all the controls in each separate instance of this custom TabPage class will already be there, just like instantiating multiple instances of some Form you created.
I'm converting my idl file to a tlb file, which now works fine. I have the base classes for Drag and Drop in the file, but when I convert it to a dll via tlbimp, i get a lot of errors, that leads me to believe that I am missing out on a large number of type definitions.
Where do I go to import these?
Aditionaly, when comparing my DLL with the windows form DragDrop methods, a lot of my int32's are replaced with UInt32. Why is this the case?
All my return values are void, wheras, in the IoleDataObject, they are almost all exclusively int.
Looking at the reflector decompilation, some of the objects that my version tries to interpret and convert but fails to, are all stored as object, i.e. IEnumStatData and IAdviceSink. How would I set up tlbimp to set it up this way?
Also, many of my types now come with & appended after them when they are used in method descriptions. Why is this?
My compiled version seems to have added object's for all the base types, Bitmap, clip format, metafile, pallete, and a whole heap of IWinTypes and IAdviseSink.
I don't know where these are actualy coming from. Do they exist in the .NET run time assembly already? I thought they did.
By default, tlbimp.exe transforms any method signatures with an [out, retval] parameter such that it because the return type of the method. Since Microsoft developers also typed these methods, you can sometimes get away with returning an int to represent the HRESULT (so it would seem), but you can still return various HRESULT codes by throwing the COMException with an appropriate errorCode parameter value - even success codes like S_FALSE.
As far as all the interfaces that were imported, these interfaces, structs, etc., are used by the interfaces you imported so they must be imported too, being that they are dependend types of the interfaces' methods that you imported (or struct member types, etc.).
If you want more control over the method signatures, you should type them yourself.
So what I have will still work? i'll just have to handle the Uints and IntPtr's differently?
What about deffining the classes that didn't get ported properly?
STGMEDIUM failed completely, and is handled as an intptr. I can define one myself, but I'm curious as to why it failed. I'm not sure where it's declared, as there are many STGMEDIUM type classes declared through the SDK import IDL's, though none actualy follow the name STGMEDIUM or tagSTGMEDIUM directly.
Many of the other interfaces, structs etc, failed to be marshaled, I got a lot of errors that looked like they failed down to a base system type.
Clipformat and STGMEDIUM in particular are my two biggest concerns, and another problem is with a Byte array that used an equation to determine the size.
I will have a crack at porting some of these to C# manualy if the whole tlbimp failes, but i'd like to go back to it due to the fact that I only had a slight brush with it.
(As opposed to MIDL which works fine now I have figured out how things work, but it took long enough)
If you are ready to lose some of your hair, then you can edit the interop assembly (ildasm) by hand and then recompile it with a proper marshalling (ilasm).
Things to know about tlbimp.exe :
- it's a great tool but it doesn't export all of the content of IDL files.
- you need an actual tlb file (embedded or not), if not tlbimp.exe will fail miserably
- The .NET IntPtr type is the lowest common denominator for some struct. It shouldn't be a surprise that tlbimp exports an IDL-defined struct to a mere IntPtr when either 1) the struct is not defined as tlbimp.exe expects it to be 2) the structure is overly complex. Resulting in an IntPtr means that you have to marshal the struct back and forth yourself, that's not a big deal though since the Marshal class in the InteropServices namespace provides the API for just that.
I would like to create a string bitmap and that string should be able to customized by user.
I know I can use Graphics.DrawString() to draw a string over the window, but phycially, I want to generate a bitmap for that. Futhermore, I would like to collect the memory bits of that bitmap, because I need to do some calculations or adjusting its colors .
I am devloping a window form to List the files under a specific folder. I am using FolderBrowserDialog class for user to select a specific folder. Once a specific folder is selected I list all the files under that folder.
My problem is when Folder Browser window opens It does not show the tree view of Directory structure. Just a blank area instead. At the bottom of the window, it shows
three button " Create new folder ", "OK" & "Cancel". Appreciate any help to resolve this problem.
Code for Folder Browser:
FolderBrowserDialog folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
folderBrowserDialog1.SelectedPath = Directory.GetCurrentDirectory();
DialogResult result = folderBrowserDialog1.ShowDialog();
if( result == DialogResult.OK )
directoryPath = folderBrowserDialog1.SelectedPath;
Everything looks right, so you should try debugging. See what the value of folderBrowserDialog1.SelectedPath is after assigning the return value of Directory.GetCurrentDirectory. If you are setting a RootPath (assuming you didn't copy and paste the code fragment directly), make sure Directory.GetCurrentDirectory is a child of that RootPath.
Kinda new to the .NET/C# thing so maybe there's a simple solution for this (I hope). I'm creating a subclass of ListBox, but instead of normal listbox items I want it to display panels (containing various other controls). I know how to make it an "ownerdraw" listbox and I've provided the proper measurements for each panel in the "MeasureItem" override, but I don't know what to do in the "DrawItem" override in order to get the panels to be displayed. How does one do this? All the examples of ownerdraw listboxes I've seen use the Graphics.DrawRectangle(...) and Graphics.DrawString(...), etc., commands to draw things, when I really just want the panel control to draw itself.
I'm working on using RSA encryption in a Form Application. I'm stuck, How do I get access to the Public Key of the Public/Private Key pair ? Can I access it directly through RSAParameters ? I need to be able to send it over a socket.
Can I send the whole RSAParameters class over the socket some how ?
I'm triing to Serialize the RSAParameters Class but ehte resulting buffer is blank:
public byte  GetPublicKeyBuff()
RSAParameters result = new RSAParameters();
BinaryFormatter formatter = new BinaryFormatter();
result = rsa.ExportParameters(false);
Stream s= new MemoryStream();
byte PubKey = new byte[iSize];
BinaryWriter bw = new BinaryWriter(File.OpenWrite("c:\\temp\\test\\pubkey.dat"));
Hello, i am trying to make an application that will be nested within another app and will 1) create a BackUP folder if it doesn't exist, and 2) it will check for a number of files to see which exist and which not in the backup and act as told.
So far i made it check for the backup folder and create one but i can't execute more than one 'if' expression, thus i get stuck with only copying (back up) only one file. here's a fragment of the the code:
So, your array contains on even indices the backup file name and on odd indices the original file name...
From the code you have the easiest change is to delete the else because as soon as the first if condition is satisfied all others will be ignored because that are something "else".
The same would be true of the switch. By the way, Fall through is not permitted in C# switch statements unless is it falling through without doing anything.
// Do somethingcase2:
// This is not permitted because statements exist in the above casebreak;
// This is permitted. 3 falls through because nothing is done until// it gets to 4.break;
Of course you would have to set your array to be the correct length.
When Monty Python meets Star Trek: WHAT is your name? Captain Jean-Luc Picard. WHAT is your quest? I seek the Holy Grail. WHAT is the average velocity of a Bird of Prey? Romulan or Klingon? I ... I don't know AAAAAHHHHH!
Last Visit: 31-Dec-99 19:00 Last Update: 4-Feb-23 22:06