|
See my indirect reply to part of your question at http://www.codeproject.com/script/comments/forums.asp?msg=889799&forumid=1649#xx889799xx
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Please i want to creat a button when i click on it open other form.if i added a new form to the project how can i open it by clicking a button in anther form???!!!.
|
|
|
|
|
hi,
No one is perfect in any language.Language is used for convince your idea or things to others. But here i don't know what you are trying to convince.
so please write your queary which help others to post answers.
Don't feel bad i can help you out.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Suppose Form1 contains button1 and when user clicks button1, you want to display Form2. Below code does the same.
private void button1_Click(object sender, System.EventArgs e)
{
using (Form2 f = new Form2())
{
f.ShowDialog();
}
}
|
|
|
|
|
Firstly create an instance of your new form
Form2 myForm = new Form2();
Then show the form
myForm.Show();
If this was not what you were trying to do then re-post your problem.
Kev Pearman MCP
|
|
|
|
|
Hi,
Is it possible for a base class to determine with reflection the type of the derived class that called the base constructor?
Something like the following code:
--------------------------
class DerivedClass : BaseClass
{
public DerivedClass() : base() {} // 1.
}
class BaseClass
{
public BaseClass() // 2.
{
Console.WriteLine("I was constructed by the following derived class: "+ ... );
}
}
---------------------------
Thanks,
Pete
|
|
|
|
|
Yes it can..
using System;<br />
namespace ConsoleApplication1<br />
{<br />
class Class1<br />
{<br />
[STAThread]<br />
static void Main(string[] args)<br />
{<br />
c1 c = new c2();<br />
Console.WriteLine("I was constructed by the following derived class: "<br />
+ c.GetType());<br />
c = new c3();<br />
Console.WriteLine("I was constructed by the following derived class: "<br />
+ c.GetType());<br />
}<br />
}<br />
class c1<br />
{<br />
public c1(){}<br />
}<br />
class c2 : c1<br />
{<br />
public c2(){}<br />
}<br />
class c3 : c1<br />
{<br />
public c3(){}<br />
}<br />
}
|
|
|
|
|
PJules wrote:
Is it possible for a base class to determine with reflection the type of the derived class that called the base constructor?
Ok had to read that a few times. I think I have, quite tricky! I think this will explain what you need:
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Reflection;
#endregion
namespace ConsoleApplication1
{
class Program
{
protected Program()
{
Console.WriteLine("{0:X8}\t:default", GetHashCode());
foreach (StackFrame sf in new StackTrace().GetFrames())
{
MethodBase mi = sf.GetMethod();
Console.WriteLine("{0}::{1}", mi.DeclaringType, mi);
}
}
protected Program(string overload)
{
Console.WriteLine("{0:X8}\t:overload", GetHashCode());
foreach (StackFrame sf in new StackTrace().GetFrames())
{
MethodBase mi = sf.GetMethod();
Console.WriteLine("{0}::{1}", mi.DeclaringType, mi);
}
}
protected Program(int someother) : this(someother.ToString())
{
Console.WriteLine("{0:X8}\t:overload -> someother", GetHashCode());
foreach (StackFrame sf in new StackTrace().GetFrames())
{
MethodBase mi = sf.GetMethod();
Console.WriteLine("{0}::{1}", mi.DeclaringType, mi);
}
}
static void Main(string[] args)
{
Derived a = new Derived();
Derived b = new Derived("foo");
Derived c = new Derived(100);
Derived d = new Derived(true);
Console.ReadLine();
}
}
class Derived : Program
{
public Derived() : base("dummy") { }
public Derived(string overload) : base(100) { }
public Derived(int crossref) : base() { }
public Derived(bool v) : this() { }
}
}
Output:
03B95145 :overload
ConsoleApplication1.Program::Void .ctor(System.String)
ConsoleApplication1.Derived::Void .ctor()
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
00AE0419 :overload
ConsoleApplication1.Program::Void .ctor(System.String)
ConsoleApplication1.Program::Void .ctor(Int32)
ConsoleApplication1.Derived::Void .ctor(System.String)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
00AE0419 :overload -> someother
ConsoleApplication1.Program::Void .ctor(Int32)
ConsoleApplication1.Derived::Void .ctor(System.String)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
03DEA808 :default
ConsoleApplication1.Program::Void .ctor()
ConsoleApplication1.Derived::Void .ctor(Int32)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
02A8E964 :overload
ConsoleApplication1.Program::Void .ctor(System.String)
ConsoleApplication1.Derived::Void .ctor()
ConsoleApplication1.Derived::Void .ctor(Boolean)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
Got it? Good
top secret xacc-ide 0.0.1
|
|
|
|
|
Thank You!
That's a very helpful code snippet
How safe is this stack tracing?
I mean, are there no risks due to asynchronous interceptions by the CLR?
Thanks
Pete
|
|
|
|
|
PJules wrote:
How safe is this stack tracing?
I dont think there is anyhting unsafe about it, just a heavy operation.
top secret xacc-ide 0.0.1
|
|
|
|
|
Hello All,
I've been playing around with DirectSound in the past month or so. As a first project I set out to write an application that does the following:
1. Playback wav files
2. Record wav files
3. Stream audio from the sound card to the speakers.
I was able to do (1) without a problem and (2) after a bit of a struggle.
However, I just don't seem to be able to do (3). It would seem to be trivial, considering I've done (1) and (2).
My scheme is this:
CaptureBuffer -> ByteArray -> MemoryStream -> SecondaryBuffer
I'm running into problems in the ByteArray -> MemoryStream portion and there on.
I realize that this may not be a topic a majority of the users of this forum are interested in and am absolutely willing to continue this discussion privately through email: (nietzschedisciple@gmail.com)
I would really appreciate it if somebody could email me some working code snippets (I don't want to see your entire program, just the parts relevant to my problem).
I think I understand what I'm supposed to do THEORETICALLY. The problem is in translating it to code.
Thanks for reading!
|
|
|
|
|
If you don't get your answer here, try the forums on http://www.gamedev.net, plenty of people there I'm sure have tried this, or would at least have an idea.
|
|
|
|
|
John, thanks for your suggestion. However, I've tried the DirectX forum there. Not too many people interested in DirectSound - more interested in the graphics aspect. I did receive a few suggestions, none too helpful.
I was wondering if any users here dabble with DirectSound...
|
|
|
|
|
Hello,
I want to get some monitor value (cpu usage, memory) of a process by using perfomance counter. The perf.counter require the instance name but currently I dont know how to get the image name of a process exactly!
For example,
if process name is SampleAppTest.exe:
In Win2K3 image name will be SampleAppTest.exe
In Win2K image name will be SampleAppTest.e (15 chars)
if 2 users run SampleAppTest.exe in same computer, the required image name will be SampleAppTest.exe for user 1, SampleAppTest.exe#1 for user 2, ...
(SampleAppTest.e for user 1, SampleAppTest.e#1 in Win2K)
So how to supply correct image name to perf.counter ??
|
|
|
|
|
does the visual studio .NET IDE provide a local VCS system ? ( simlar to that found in like in Intelij idea [tools > local VCS])..Is there way to enable CVS found in File>Source control...?
samitha
|
|
|
|
|
Hi all ,Forgive my bad english,please.
I'm new user in c#.I have one problem about struct and pointer.
I want to create c# API that call DLL file in c++ .
//DLL sample as below(c++):
struct TESTA
{
DWORD A;
WORD B;
WORD C;
BYTE D[16];
};
typedef TESTA* LPTESTA;
BOOL CBook::InitialButton(LPTESTA pInfo)
{
//statement
return true;
}
//C# code as below:
unsafe public class callDLL
{
[StructLayout(LayoutKind.Sequential)]
public struct TESTA
{
public int A;
public ushort B;
public ushort C;
[MarshalAs(UnmanagedType.ByValArray, SizeConst= 16)]
public byte[] D;
}
[DllImport("dllname.dll")]
unsafe public static extern bool InitialButton(void* pInfo);
}
public class Initialize_sequence
{
unsafe static void Main(string[] args)
{
callDLL.TESTA pInfo=new callDLL.TESTA();
Console.WriteLine(Marshal.SizeOf(pInfo));
callDLL.InitialButton(&pInfo); //error happen
}
}
error message show "Can't get position and size of Mananged type"
Any one can provide idea for me ? Thanks.
hello ALL..^^
|
|
|
|
|
Instead of using the "unsafe" keyword in C# and using void* in the extern function signature, try this:
<br />
public static extern bool InitialButton(ref TESTA pInfo);<br />
and in the call to the function you would just do
<br />
callDLL.InitialButton(ref pInfo);<br />
The marshaller should automatically treat this as a pointer.
|
|
|
|
|
I modified it as your suggestion.
It is ok .
Thank you very much.
hello ALL..^^
|
|
|
|
|
Hi,
I am having two windows application Client and Host and one class library Customer. Host application holds the instance of Customer class. Customer class contains one windows form. It exposes a method to show that form.
Client application connects to Host through Remoting and get the Customer class.
When I try to open that form through the proxy_object, the form is being shown but the controls are not painted and it is in a hanged state.
Can anybody help me on this.
Thanks in advance
Regards,
Sabari.
|
|
|
|
|
You have to invoke the showing of the form so this is executed in the context of the main UI thread. Take a look at the Control.Invoke method.
www.troschuetz.de
|
|
|
|
|
How do I enable tracing? I put a "#define TRACE" in my code and it still does not print:
#define TRACE
using System;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
System.Diagnostics.Trace.WriteLine("testing trace");
}
}
}
thanx, amir
|
|
|
|
|
|
Hey Kevin,
Thanx for the help. The example in your link pointed me in the right direction. It looks like you need this line: "<debug|trace>.Listeners.Add(new TextWriterTraceListener(Console.Out));"
it tells the output where to go. you can specify the console's output or a file.
Trace is enabled automatically by .NET. So here is a sample of how to enable and disable different modes of tracing using trace or boolean switches:
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
BooleanSwitch boolSwitch = new BooleanSwitch("ABooleanSwitch",
"Demo bool Switch");
TraceSwitch traceSwitch = new TraceSwitch("ATraceSwitch",
"Demo trace switch");
// Set the switch values programmatically
boolSwitch.Enabled = false;
traceSwitch.Level = TraceLevel.Info;
Trace.WriteLineIf(boolSwitch.Enabled, "bool switch is enabled");
Trace.WriteLineIf(traceSwitch.TraceInfo, "traceSwitch.TraceInfo is enabled");
Trace.WriteLineIf(traceSwitch.TraceError, "traceSwitch.TraceError is enabled");
thanx, amir
|
|
|
|
|
I have a solution with two projects in it, a Managed C++ project and a C# project which is using (dependant on) the Managed C++ project. Is there any way to "Staticlly Link" this Assembly into the C# EXE. I need to keep them as seperate project for source control reasons so I can't move the files into that project directly.
Anyone know how to do this?
Thanks!!!
|
|
|
|
|
AFAIK you cannot. Even if you could move the source code in to one project it still won't work as the source code is in two different languages and you cannot mix languages in a single project.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|