|
Hi Heath,
thanks for replying. actually i am not very good at vb, but i am a little comfortable programming with c#. that is one reason i wanted to convert that code into c#. also, i wanted to know more about coupling and de-coupling, if i want to run my .dll project (which is going to be plug-in) as an executable at the same time. if you suggest any examples or material to follow-up the understand the architecture design, that will be GREAT. and also i didn't knew that my question was posted more than one time, and sorry about that..
Thanks
vijju
|
|
|
|
|
Coupling and decoupling has nothing to do with how code is executed - it has to do with how code is referenced.
Knowing the C# language doesn't mean you know .NET. If you want to learn more, I suggest you read the SDK, which should be installed on your machine (it is installed by default with VS.NET, but can be installed separately) and available online at http://msdn.microsoft.com/library/en-us/dnanchor/html/netfxanchor.asp[^]. Understanding at least the basic concepts of the CLR (like what assemblies are) is important.
Since you didn't tell me what g_pPropSet is defined as, I can only assume it's defined in the Microsoft.VisualBasic.Compatibility assembly. As I mentioned before - converting the code isn't a good idea, especially if you're new to .NET; you'll never learn anything that way. So, just converting the code to C# won't get rid of the assembly dependency - you'll have to rewrite it to use a similar class. Judging by what you seem to be trying to do, a suitable class might be the StringDictionary as I mentioned in my other reply.
If you want to know more about architecting .NET solutions, visit http://msdn.microsoft.com/patterns[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Besides, do you maybe want to put this in context? What are you trying to do? Extract a value from a collection? If all you did was convert from one language to another, you're constrained by what the rest of the code did.
Now, if you convert the concept, you could use many types to do this. For example, you could use a Hashtable or StringDictionary (or several other things in the BCL) to store string key/value pairs and refer to them by name:
StringDictionary dict = new StringDictionary();
dict["One"] = "Apple";
dict["Two"] = "Orange";
dict["Three"] = "Banana";
Console.WriteLine(dict["Two"]); When moving from one application framework to another, don't just convert your code. Advancements are made with newer frameworks. If all you're doing is porting your code just to run on the .NET Framework, you're doing a very stupid thing (any article by a decent author will tell you as much) - if it works, don't change it. If you have to change it to add new functionality later and to be maintainable by less-than-knowledge programmers, then change it in steps.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My VB is a bit rusty but I think this is your answer.
private string GetSingleProperty(string elementName)
{
object Values = g_pPropSet.GetProperty(elementName);
if (Values == null)
return String.Empty;
if (Values.GetType() != typeof(String))
return String.Empty;
return (string)Values;
}
|
|
|
|
|
That would still require the Microsoft.VisualBasic.Compatibility assembly, since whatever Type g_pPropSet seems to be from there (since everything else is defined in the BCL assemblies). He doesn't want to reference that assembly, even though it really doesn't matter.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how do we get our column width auto adjusted to fit the length of the column header text when it's displayed in dataGrid.
Thanks
|
|
|
|
|
There is no automatic adjustment for the DataGrid like there is for the ListView (not data-bindable). You must either guess at design-time, or when the DataGrid is loading, enumerate the DataGrid.TableStyles collection property, and enumerate each's GridColumnStyles collection property. Get the text and use Graphics.MeasureString using the Font property of the DataGrid . Set the current column's Width accordingly.
This only works when 1) you're using explicitly defined table and column styles before data is bound, or 2) after data is bound to the DataGrid .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi everyone.
I have an add-in that saves Outlook messages in a customer database.
I've created a toolbar button that's loaded in the Word E-mail toolbar and in the Outlook Standard toolbar. Everything works great in Outlook, but when I open up a new message (Word, that is) I can't get the information from the mail fields, for example "to" and "bcc".
This code gives me the message content:
Word.Document doc = ((Word.Application)myApp).ActiveWindow.Document;
System.Windows.Forms.MessageBox.Show(doc.Content.Text);
So I thought that
Outlook.MailItemClass mail = (Outlook.MailItemClass)doc.MailEnvelope.Item;
should give the mail information I'm looking for, but nope.
How do I find the mail information?
Cheers,
Sven
|
|
|
|
|
Hi,
can anyone help me converting vb.net code given below into c#. also, if i have .dll project, how do i convert the .dll executable at the same time.. i appreciate ur help. Thanks...
vb.net code
-------------
Private Function GetSingleProperty(ByRef sElementName As String) As String
Dim vValues As Object
vValues = g_pPropSet.GetProperty(sElementName)
If IsNothing(vValues) Then
GetSingleProperty = ""
ElseIf VarType(vValues(LBound(vValues))) <> VariantType.String Then
GetSingleProperty = ""
Else
GetSingleProperty = vValues(LBound(vValues))
End If
End Function
vijju
|
|
|
|
|
Why bother? Are you forgetting that all managed languages compile down to Intermediate Language? The source language doesn't matter; the associated compilers compiles that to IL and assemblies it in a module, which then gets embedded into an assembly along with embedded resources (if any). So why bother redoing it in C#? Just have your C# project reference the VB.NET assembly and viola'! The BCL (base class library) assemblies are written in C#, but you can use them in VB.NET, MC++, J#, and all the other languages, can't you?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Help! Help! Help!
I have a usercontrol that have a collection contain of a class(or struct). I want the collection be save autamatically with form's code.
my code:
public class Struct1<br />
{<br />
private int m_x ;<br />
public int x <br />
{<br />
get{return m_x;}<br />
set{m_x=value;}<br />
}<br />
private string m_y ;<br />
public string y <br />
{<br />
get{return m_y;}<br />
set{m_y=value;}<br />
}<br />
}<br />
private Struct1 m_struct ;<br />
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]<br />
<br />
public Struct1 STRUCT<br />
{<br />
get{return m_struct ;}<br />
set{m_struct=value;}<br />
}<br />
<br />
public class MyCoulumnClollectionClass : CollectionBase<br />
{<br />
<br />
public Struct1 this[ int index ] <br />
{<br />
get <br />
{<br />
return( (Struct1) List[index] );<br />
}<br />
set <br />
{<br />
List[index] = value;<br />
}<br />
}<br />
public int Add( Struct1 value ) <br />
{<br />
return( List.Add( value ) );<br />
}<br />
<br />
public int IndexOf( Struct1 value ) <br />
{<br />
return( List.IndexOf( value ) );<br />
}<br />
<br />
public void Insert( int index, Struct1 value ) <br />
{<br />
List.Insert( index, value );<br />
}<br />
<br />
public void Remove( Struct1 value ) <br />
{<br />
List.Remove( value );<br />
}<br />
<br />
public bool Contains( Struct1 value ) <br />
{<br />
return( List.Contains( value ) );<br />
}<br />
}
|
|
|
|
|
How many more times must I say, that if the DesignerSerializationVisibilityAttribute isn't giving you the effect you want, you will have to derive your own CodeDomSerializer and reference your implementation in the DesignerSerializerAttribute that would attribute your collection property? Those are your only two options, the the one option obviously doesn't work. Do the math.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi.
Thank you.
But i try to using CodeDomSerializer , but it is failed.
|
|
|
|
|
Then you're doing something wrong, because it works for many classes in the BCL as well as many other third-party controls I've used that must use a CodeDomSerializer . But since you didn't say why it failed (exceptions, problems, don't know what you're doing, whatever), I can't really help you.
Learn to be specific when asking for help, because saying things like "it failed" doesn't help at all.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I create a group of radio buttons so the user can select the database they want.
When the user clicks one of the buttons, the event issues a detatch and re-attach to the proper database.
The problem I am having is that during the form load I read the registry to find the current selection and then set the radio buttons showing which one has been checked by issuing a xyz.Checked = true;
This then forces a click event which causes the db to detach/reattach.
I only want the db to detach/reattach when the radio button is cliked by the user not during load.
I get the same stuff using the CheckedChanged event and setting a bool first time pass doesn't seem to do the trick either.
Thanks,
Craig
|
|
|
|
|
The obvious solution is to use a state variable. While loading, this variable could be unset. Once the form is done loading (say, in the OnLoad override in your Form ), set this variable. In your client event handler, determine if the variable is set. Only then do you execute your code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have developed a Windows service application running on my machine. I was trying to implement a screen capture utility for it. I have a working (at least in clasic Windows form application) screen capture class.
But when I try to capture screen from my service it saves a file and the content is all black.
Did anyone try to capture screen from Windows service application and manage to get it work? Any ideas?
Thank you. Milos.
"some people never go crazy
oh how trully horrible life they've lived" -- Charles Bukowski
|
|
|
|
|
The service has to be enabled for interaction with the desktop. After you install the service using the ServiceProcessInstaller and ServiceInstaller , go to your services control panel, double-click on the service to show its properties, then click the security tab. Select "Allow service to interact with desktop". If you don't, the service does not get it's own window station and the screen would be black (frankly, I'm surprised it work at all, meaning you must have caught an exception somewhere and continued drawing a background or something).
You could also enable this during installation, but you'll have to do so manually. In your own Installer class, override OnCommitting and use the registry classes in the Microsoft.Win32 namespace to change the registry key accordingly (bitwise OR the Type key under the service key - using the service name, not the display name - with 256, IIRC).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm trying to use PropertyGrid to set the props of a remote object. At first it looked ok, but then I complicated it by adding plugins. So now I got the following class tree:
Node : MarshalByRef
Handler : Node
[plugin] : Handler
The plugin object is instansiated by sending the class name to the server, who looks it up in the assebly, creates it and returns it.
// client call
private void NewHandler(object sender, EventArgs e)
{
MenuItem mi = sender as MenuItem;
Handler node = server.CreateHandler(mi.Text);
handlersNode.Nodes.Add(new NodeFacet(node));
propertyGrid1.SelectedObject = node;
// node.NodeChanged += new NodeChange(NodeChanged);
}
// server side
public Handler CreateHandler(string type)
{
Handler node = this.CreateNode(type, handlerTypes) as Handler;
Handlers.Add(node);
return node;
}
In debugger I can see that the node is of the correct subclass, but on the client side I only get the properties from my Handler and Node class.
Any suggestion?
|
|
|
|
|
Hi gurus,
Where can I find a C# sample code that shows how to send a class with DirectPlay? I can send text but I need to send binary data.
best regards.
There is no spoon.
|
|
|
|
|
Have you looked in the DirectX SDK documentation for Managed Languages? All you need is either a NetworkPacket or a GCHandle (which you can create using any type). To use a NetworkPacket , all you have to do is pass a ValueType , which is any primative, enum, or struct (they all derive from ValueType ).
So, to use a NetworkPackget :
using (NetworkPacket pkt = new NetworkPacket())
{
pkt.Write(new Point(8, 8));
client.Send(pkt, 0, SendFlags.Guaranteed);
} If you're looking for a good resource on Managed DirectX, I highly recommend Managed DirectX 9 Kick Start: Graphics and Game Programming[^]. It's a good read and includes several chapters on DirectPlay. Honestly, though, it's not too tuff, especially after reading that book. It's certainly a lot easier than many .NET Remoting applications I've designed and help write!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ah ok...
We can't send a complete class, but we can send simply a structure derived from ValueType...
in a class that handle DirectPlay, is it necessary to use trnasactions with
[Transaction(TransactionOption.Required)] ?
Or the flag SendFlags.Guaranteed is enough?
NB: thanks for the link, but the MSDN is largely enough. I just messed up with the parameters... they need to be a structure, not a class :P
There is no spoon.
|
|
|
|
|
The TransactionAttribute is for service components (i.e., COM+ services), not DirectPlay (or any DirectX). They have nothing to do with each other. You can't just mix and match APIs.
If you want to send a class, use the Client.Send overload that requires a GCHandle , as I mentioned before. Most importantly, read the docs. I know the DirectX SDK documentation sucks (NDoc[^] is free and does a better job), but at least you can see what classes and members are available; that's all I did to answer your question (since I knew the basics already).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have created a structure with basic data (bool & int) and the structure is not sent. there is an exception that tells "An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Object contains non-primitive or non-blittable data."
while the strcuture looks like this:
public struct TetrionParams
{
#region Fields
public bool DrawGrid;
public bool Draw3D;
public bool ShowGhostPolymino;
public bool ShowNextPolymino;
public int Width, Height;
#endregion
}
There is no spoon.
|
|
|
|
|
How are you calling Client.Send with this struct? More information is required to help you.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|