|
mk20 wrote: clients to be able to create instances of the remote classes and use their methods and properties.
If this was not the case, then webservices would be an excellent choice. One thing you can do, is expose all the public instance methods as public static methods throuh webservice and pass the object on which to call the method as the parameter to the static method.
You could use remoting, but if you have multiple versions of the program, things may go out of control easily.
Using webservice:
<code>public class Employee
{
public void PromoteAsSupervisor()
{
...
}
public void GiveRaise(int value)
{
...
}
public void AssignProject(Project p, Duration d)
{
...
}
}
public class MyWebService:WebService
{
[WebMethod()]
public void PromoteAsSupervisor (Employee employee, params object[] parameters)
{
if (employee==null)
{
throw new ArguementNullException("employee");
}
else
{
employee.PromoteAsSupervisor();
}
}
[WebMethod()]
public void GiveRaise (Employee employee, params object[] parameters)
{
if (employee==null)
{
throw new ArguementNullException("employee");
}
else
{
employee.GiveRaise((int) parameters[0]);
}
}
[WebMethod()]
public void AssignProject (Employee employee, Project p, Duration d)
{
if (employee==null)
{
throw new ArguementNullException("employee");
}
else
{
employee.AssignProject(p, d);
}
}
[WebMethod()]
public void InvokeMethod (object obj, string method, params object[] parameters)
{
}
}</code>
- Malhar
|
|
|
|
|
I wanted to try and create a new DataGridViewColumnHeaderCell class that would allow me the option of having the column headers displayed vertically instead or horizontally. So I created a new class that inherits from DataGridViewColumnHeaderCell and overrode the Paint and GetPreferredSize methods. This seems to work okay so long as all my columns are visible from the start (except I can't see the result at design time, which is annoying). The problem is when I start with a column that is not visible and then make it visible later so weird things happen. The columns are set to autofit their contents but the width and height aren't getting set correctly. Here's my override for GetPreferredSize
protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
if (!verticalText)
{
return base.GetPreferredSize(graphics, cellStyle, rowIndex, constraintSize);
}
else
{
StringFormat sf = new StringFormat(StringFormatFlags.DirectionVertical);
SizeF size = graphics.MeasureString((string)this.FormattedValue, this.DataGridView.Font, constraintSize, sf);
return new Size((int)size.Width, (int)size.Height);
}
}
Is there something I'm missing here? Is there something else I need to override? Has anybody else tried something similar?
I would at least like the width to be set correctly as I can just manually set the height of the header row to something sufficient.
Thanks
|
|
|
|
|
I'm using Reflection to extract Property/Method/Event/Field information from an assembly. Assuming that I have an object of type [Property|Method|Event|Field]Info , how do I know if the implementation is derived from the base class or if it has been overriden? I need to know how to make this distinction. I tried various BindingFlags option but no luck yet.
In the following example, when I retreive all Properties for Supervisor class, I only want "EmployeesUnderMe" returned in the collection. I should not have "Salary" and "Bonus". I SHOULD have "Bonus" if Supervisor class overrode the property. Similarly, when I invoke "GetMethods(...)" on Supervisor class, I want to be ablel to distinguish that "ToString()", "GetHashCode()" etc are defined by the "object" class and NOT the Supervisor class.
<code>
public class Employee
{
public double Salary
{
get {...}
set {...}
}
public virtual Bonus
{
get {...}
set {...}
}
public Employee()
{
...
}
}
public class Supervisor:Employee
{
public Employeee[] EmployeesUnderMe
{
get {...}
}
public Supervisor()
{
}
}
</code>
Thanks for your help.
- Malhar
|
|
|
|
|
malharone wrote: I tried various BindingFlags option but no luck yet.
BindingFlags.Declared only
I think you can also try see if the methodinfo's declaredtype and reflectedtype is the same.
|
|
|
|
|
Thank you .. that did the trick. It is much better to know the project has ~7,000 methods as opposed to 150,000 methods!
- Malhar
|
|
|
|
|
Hi,
I have to pass a native Struct from my C++ DLL into my C# program.
The problem is that the struct contains a C++ "union" member.
Can someone recommend a good way to marshal the struct into my managed code?
struct NATIVE_STRUCT
{
DWORD Value1;
DWORD Value2;
union
{
STRUCT1 Member1;
STRUCT2 Member2;
} UnionMember;
};
Thanks a lot,
Rich
|
|
|
|
|
Nevermind...I found the answer.
You have to declare the union member as a struct and use various attributes to describe the physical layout of the struct, such as the [FieldOffset()] attribute.
|
|
|
|
|
Troposphere wrote: I found the answer
There are various tricks you can use in marshalling, just as long as the layout stays the same
|
|
|
|
|
I have a C# Windows Forms app, and I want to launch a whole separate application (another .exe file) when the user clicks a button.
What class and method do I use? It should work just like Start -> Run on the Windows Task Bar.
Thanks,
Mark
|
|
|
|
|
You can use the Process class (part of the System.Diagnostics namespace)
using System.Diagnostics;
...
Process.Start("<path to .exe>");
Cheers,
Will H
|
|
|
|
|
I have this number from which I have to read first few number depending on another number. What is the best way to do that.
For example ... NumToread = 3 , number = "4567889465"
answer should newNum = 456
i can do that using for (int i=1;i<=NumToread ;i++)
does any one knows better way ...
As you can say .. I am very new to programming
Thanks
CPP
Thanks
|
|
|
|
|
You should use the String.Substring() method.
int numToRead = 3;<br />
string buf = "123456789";<br />
buf = buf.Substring(0, 3);
|
|
|
|
|
Thanks
Thanks
|
|
|
|
|
hi all!
my problem
i have a project using .NET 2 in vs.net 2005
in a DataSet i have data from an access-db.
the connection string is stored in the Properties.Settings.Default ...
what i want is that i can change the *.mdb file during runtime so that each user of the programm can set its own db file.
does anyone know how i can do this???
|
|
|
|
|
I don't see the probblem.
If the user is running his program on his computer then you can do whatever you want, no?
If you have a web page then simply store the file name in a session or something like that.
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
I have a MainForm (MDIParent), a ChildA form and a Child1OfChildA Form. I have a Panel controll on ChildA Form, How can i place Child1OfChildA on this panel controll on ChildA from?
Thanks
|
|
|
|
|
I have a c# program which retrieves registry settings & writes them out to a .reg file for storage on a network so some application settings can easily be restored after an operating system upgrade, etc. Everything was going just fine until I came across a value of type dword.
If I manually export it from the registry, this is how the name and value look.
"Number of Macros"=dword:00000012
The .GetValue method brings the value in as type System.Int32 with a value of 18 (there are 18 macros defined in that app). Is anyone familiar with this dword type and what I would convert Int32 to to get this value of 00000012?
Thanks in advance for any help!
Lara
|
|
|
|
|
The dword type is a 32-bit signed integer on 32-bit systems. The output you are getting from the registry is 0x00000012 which is 18 in hex. The registry stores dword values in hex. You could always do a decimal to hex conversion to convert 18 to its hex value.
Andy
Deus caritas est
|
|
|
|
|
Got it. Excellent. Thanks!
|
|
|
|
|
I get this error when I try to use implement the IEnumerable interface:
Error 1 'generics.GenStack<t>' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'generics.GenStack<t>.GetEnumerator()' is either
static, not public, or has the wrong return type.
Here is the code segment:
// Custom Stack - designed to accept class instances only
public class GenStack<t>: IEnumerable<t>
where T : class
{
private T[] stackCollection;
private int count = 0;
// Constructor
public GenStack(int size)
{
stackCollection = new T[size];
}
public IEnumerator<t> GetEnumerator()
{
string totList = "";
for (int i = 0; i < count; i++)
{
yield return stackCollection[i];
totList+= stackCollection[i]+" ";
}
object ob = totList ;
yield return (T)ob;
}
.
.
}
I am implementing the GetEnumerator(), though. Am I missing something?
Thanks in advance
|
|
|
|
|
A little curious by your code snippet. Try:
<code>
public class GenStack<T> : IEnumerable<T> where T:class
{
public GenStack(...) { ... }
public IEnumerator<T> GetEnumerator() { }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { }
}
</code>
-- modified at 16:53 Tuesday 14th February, 2006
|
|
|
|
|
Can someone tell me how exact it is to customize the size of the buttons in the MessageBox control? I am planning to make my MessageBox by inheriting the one in the .net library.
I know there is something to do with the onPaint event handler, but i am not very sure
thx for all your help
|
|
|
|
|
As far as I know you cannot inherit the one in the .NET library since this is simply a wrapper around the Win32 MessageBox functions.
What I have done is to use a CBT hook to hook the MessageBox right before it is displayed, and in the CBT_ACTIVATED I can change/add/delete controls on the MessageBox. You can get the control ids using Spy++ on any MessageBox. There is a lot of interop involved with this but it works fine. You need to learn about CBT hooks and P/Invoke with .NET to make this work.
I hope this helps.
Andy
Deus caritas est
|
|
|
|
|
Why not just create a dialog form that is your own custom MessageBox? You then could use any controls in it you want.
Paul
|
|
|
|
|
Hi:
does dotnet/c# offer any smart and automated ways to preserve user preferences in GUIs such as controls users like to have checked or unchecked?
Thanks, smurfy
|
|
|
|