|
You want to write a C# COM object ? There's a wizard for that, I thought.
Being COM, it will work like any COM app, I'd have thought. Otherwise, it wouldn't be COM.
Your other option is to use C++/CLI to call C# libraries within your MFC app.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
What do you mean in there is a wizard for it ? how i getting to this wizard ?
|
|
|
|
|
Dear All,
If have the following question. I have two forms. On form one I open another form with the following code :
Form f = new Form();<br />
f.ShowDialog();
A new instance of that Form opens. However .. in form B I want to run a method from Form A. I have to reference an object.
FormA a = new FormA<br />
a.Method();
This works fine, however it opens a new instance of FormA and run the method in the new instance, while what I really want it to do is go back to the previous FormA ( already open ) and run the Method on that form.
Any suggestions ?
thx !!
|
|
|
|
|
Call the method before you do the ShowDialog
Form f = new Form();
f.Method();
f.ShowDialog();
Hope that helps.
Ben
|
|
|
|
|
Rick van Woudenberg wrote: however it opens a new instance of FormA
Yes, of course.
You can do two things.
1 - pass the instance of Form1 in to Form2 ( hack )
2 - define a delegate between the two forms, so that calling a method in form2, runs code in Form1.
There are tutorials on how to use delegates on code project.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
FormA a;
...
...
private void call_Method_On_Form_A()
{
if(a == null)
a = new FormA;
a.Method();
}
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
I use modified Rockford Lhotka excellent SetPropertyValue()
from DataMapper class to load objects from database.
My entity object property names are mixed case.
DataReader returns lower-case only column names.
So SetPropertyValue() cannot map columns to property names.
How to change this code so that it does not depend on the propertyName case ?
public static void SetPropertyValue(
object target, string propertyName, object value)
{
PropertyInfo propertyInfo =
target.GetType().GetProperty(propertyName);
if (value == null)
propertyInfo.SetValue(target, value, null);
else
{
Type pType =
Utilities.GetPropertyType(propertyInfo.PropertyType);
Type vType =
Utilities.GetPropertyType(value.GetType());
if (pType.Equals(vType))
{
propertyInfo.SetValue(target, value, null);
}
else
{
if (pType.Equals(typeof(Guid)))
propertyInfo.SetValue(
target, new Guid(value.ToString()), null);
else if (pType.IsEnum && vType.Equals(typeof(string)))
propertyInfo.SetValue(target, Enum.Parse(pType, value.ToString()), null);
else if (pType.IsEnum && vType.Equals(typeof(decimal)))
propertyInfo.SetValue(target,
Enum.Parse(pType, value.ToString()), null);
else
propertyInfo.SetValue(
target, Convert.ChangeType(value, pType), null);
}
}
}
}
}
Andrus
|
|
|
|
|
You could try to every where you see a ToString() add a .ToLower()
to set the property name to all lower.
The method you posted seems to be where the property value is getting set. I am not sure you can make changes to where the value is getting set to get the property name to make lower case.
Hope that helps.
Ben
|
|
|
|
|
I have a web application that references an access database in my app_data folder. Locally I can reference the db by C:/My Docs/Visual Studio 2005/Website/My Website/App_Data/myaccess.mdb
My question is, in my code how do I reference the database relatively since I do not know what drive and directories my site will be stored on? I've tried ~/App_Data/myaccess.mdb (tried this locally and it does not reference the db) and it does not connect. All suggestions welcome thanks.
|
|
|
|
|
|
I'm not exactly sure how to incorporate this into my connection string
//create an open string
string conString = @"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=C:\Documents and Settings\My Name\My Documents\Visual Studio 2005\WebSites\MySite\App_Data\td.mdb";
i've tried
@"data source=" + Server.MapPath("http://www.mywebsite.com/App_Data/td.mdb");
and get an error.
Please advise. Thanks.
|
|
|
|
|
The MapPath method takes a virtual path, not a complete url. Use just "/App_Data/td.mdb".
dboy221 wrote: and get an error.
That is way too specific. Could you be a bit more vague, please?
---
single minded; short sighted; long gone;
|
|
|
|
|
That did it. Thanks guys.
|
|
|
|
|
Hi.
I need to capture the event when the mouse leaves the panel and its left button pressed.
Can anyone help me with this?
What should i do?To write my own wndProc or ...?
Thank You.
|
|
|
|
|
You can capture the mouse, and then you will get mouse messages even when the mouse leaves your control. Then, you can capture the button click and check if the mouse is over the panel. If not, you have your event. You would then release capture of the mouse, so that the events would be passed to other controls after that.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Ok, and how i should to capture the mouse buttons click?
|
|
|
|
|
The point of capturing the mouse, is that the click event will be fired in your control, even if the mouse has left it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i have about 100 dynamically generated panels.
And i need for example press the left-mouse button on the one and then just drag the cursor down and all panels which will be on my way for example must change the color.
I think that now it is more understood able.
|
|
|
|
|
OK, sounds like you need to be handling events in the parent form, not the panel.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i have a greduation work about real time simulation.i have already modeled my robot arm on 3d max studio and i have XAML converter.but i dont know how to write my code in visual c#.net.what must i do?i have net framework 3.how can i simulate my robot arm with visual c#?please anyone writes step by step.
|
|
|
|
|
If you have a XAML converter, then I'd guess you have your model in XAML, so it shows in WPF. The next step, is to write the code that moves it. Really, your question is both too vague, and too broad for you to expect an answer in a forum to solve your issue for you. I'm not even clear on if you know the first thing about C#, if you know more about WPF than you saw in an ad somewhere, or what skills you're bringing to the table, you just sound like a confused guy who knows some buzzwords and is hoping for a magic bullet.
So, try asking your question more clearly, the answer will probably be, try to write it and ask specific questions when you get stuck.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
1)i have modeled my robot arm.
2)than i export it to XAML
which platform will i use for doing WPF project?
visual c# is enough for me?or will i use another platform?(aurora and like this?)
can u write me step by step how can i do wpf simulation? which platform i need?and which converter can be better?ok: )i dont know anything about wpf and explain me as you try to write small baby(me: )) please can u write step by step how can i do wpf project?which platform will be used in simulation?
|
|
|
|
|
Hello
[url]http://www.csharp-station.com/Tutorials/Lesson14.aspx[/url]
[code]
using System;
using System.Drawing;
using System.Windows.forms;
// custom delegate
public delegate void Startdelegate();
class Eventdemo : form
{
// custom event
public event Startdelegate StartEvent;
public Eventdemo()
{
Button clickMe = new Button();
clickMe.Parent = this;
clickMe.Text = "Click Me";
clickMe.Location = new Point(
(ClientSize.Width - clickMe.Width) /2,
(ClientSize.Height - clickMe.Height)/2);
// an EventHandler delegate is assigned
// to the button's Click event
clickMe.Click += new EventHandler(OnClickMeClicked);
// our custom "Startdelegate" delegate is assigned
// to our custom "StartEvent" event.
StartEvent += new Startdelegate(OnStartEvent);
// fire our custom event
StartEvent();
}
// this method is called when the "clickMe" button is pressed
public void OnClickMeClicked(object sender, EventArgs ea)
{
MessageBox.Show("You Clicked My Button!");
}
// this method is called when the "StartEvent" Event is fired
public void OnStartEvent()
{
MessageBox.Show("I Just Started!");
}
static void Main(string[] args)
{
Application.Run(new Eventdemo());
}
}
[/code]
And this from :[url]http://www.codeguru.com/csharp/csharp/cs_delegates/eventhandling/[/url]
[code]
using System;
//Step 1 Create delegate object
public delegate void MyHandler1(object sender,MyEventArgs e);
public delegate void MyHandler2(object sender,MyEventArgs e);
//Step 2 Create event handler methods
class A{
public const string m_id="Class A";
public void OnHandler1(object sender,MyEventArgs e){
Console.WriteLine("I am in OnHandler1 and MyEventArgs is {0}",
e.m_id);
}
public void OnHandler2(object sender,MyEventArgs e){
Console.WriteLine("I am in OnHandler2 and MyEventArgs is {0}",
e.m_id);
}
//Step 3 create delegates, plug in the handler and register
// with the object that will fire the events
public A(B b){
MyHandler1 d1=new MyHandler1(OnHandler1);
MyHandler2 d2=new MyHandler2(OnHandler2);
b.Event1 +=d1;
b.Event2 +=d2;
}
}
//Step 4 Calls the encapsulated methods through the
// delegates (fires events)
class B{
public event MyHandler1 Event1;
public event MyHandler2 Event2;
public void FireEvent1(MyEventArgs e){
if(Event1 != null){
Event1(this,e);
}
}
public void FireEvent2(MyEventArgs e){
if(Event2 != null){
Event2(this,e);
}
}
}
public class MyEventArgs EventArgs{
public string m_id;
}
public class Driver{
public static void Main(){
B b= new B();
A a= new A(b);
MyEventArgs e1=new MyEventArgs();
MyEventArgs e2=new MyEventArgs();
e1.m_id ="Event args for event 1";
e2.m_id ="Event args for event 2";
b.FireEvent1(e1);
b.FireEvent2(e2);
}
}
[/code]
I have 2 questions,
In first example ,It didn't used
But in second example,It is used
Why?
When do we use EventArgs?
|
|
|
|
|
Hello
From Programming C#, 4th Edition
[code]
namespace EventKeyword
{
// a class to hold the information about the event
// in this case it will hold only information
// available in the clock class, but could hold
// additional state information
public class TimeInfoEventArgs : EventArgs
{
public readonly int hour;
public readonly int minute;
public readonly int second;
public TimeInfoEventArgs(int hour, int minute, int second)
{
this.hour = hour;
this.minute = minute;
this.second = second;
}
}
// our subject -- it is this class that other classes
// will observe. This class publishes one event:
// OnSecondChange. The observers subscribe to that event
public class Clock
{
private int hour;
private int minute;
private int second;
// the delegate the subscribers must implement
public delegate void SecondChangeHandler
(
object clock,
TimeInfoEventArgs timeInformation
);
// the keyword event controls access to the delegate
public event SecondChangeHandler OnSecondChange;
// set the clock running
// it will raise an event for each new second
public void Run( )
{
for(;;)
{
// sleep 10 milliseconds
Thread.Sleep(10);
// get the current time
System.DateTime dt = System.DateTime.Now;
// if the second has changed
// notify the subscribers
if (dt.Second != second)
{
// create the TimeInfoEventArgs object
// to pass to the subscriber
TimeInfoEventArgs timeInformation =
new TimeInfoEventArgs(
dt.Hour,dt.Minute,dt.Second);
// if anyone has subscribed, notify them
if (OnSecondChange != null)
{
OnSecondChange(
this,timeInformation);
}
}
// update the state
this.second = dt.Second;
this.minute = dt.Minute;
this.hour = dt.Hour;
}
}
}
// an observer. DisplayClock subscribes to the
// clock's events. The job of DisplayClock is
// to display the current time
public class DisplayClock
{
// given a clock, subscribe to
// its SecondChangeHandler event
public void Subscribe(Clock theClock)
{
theClock.OnSecondChange +=
new Clock.SecondChangeHandler(TimeHasChanged);
}
// the method that implements the
// delegated functionality
public void TimeHasChanged(
object theClock, TimeInfoEventArgs ti)
{
Console.WriteLine("Current Time: {0}:{1}:{2}",
ti.hour.ToString( ),
ti.minute.ToString( ),
ti.second.ToString( ));
}
}
// a second subscriber whose job is to write to a file
public class LogCurrentTime
{
public void Subscribe(Clock theClock)
{
theClock.OnSecondChange +=
new Clock.SecondChangeHandler(WriteLogEntry);
}
// This method should write to a file.
// We write to the console to see the effect.
// This object keeps no state.
public void WriteLogEntry(
object theClock, TimeInfoEventArgs ti)
{
Console.WriteLine("Logging to file: {0}:{1}:{2}",
ti.hour.ToString( ),
ti.minute.ToString( ),
ti.second.ToString( ));
}
}
public class Test
{
public static void Main( )
{
// create a new clock
Clock theClock = new Clock( );
// create the display and tell it to
// subscribe to the clock just created
DisplayClock dc = new DisplayClock( );
dc.Subscribe( theClock );
// create a Log object and tell it
// to subscribe to the clock
LogCurrentTime lct = new LogCurrentTime( );
lct.Subscribe( theClock );
// Get the clock started
theClock.Run( );
}
}
}
[/code]
May someone explain about this part of code:
[code]
if (OnSecondChange != null)
{
OnSecondChange(
this,timeInformation);
}
}
[/code]
I don't know but I think,But I think it should be something like this:
Onsecondchange =+new secondchangehandler(funcname)...
|
|
|
|
|