|
I'm coding a MDI form application. What I really want the form (not the controls it contain) to look like is similar to Office 2003, which reflects the theme the system is using. Could someone give me some help?
Thanks!
|
|
|
|
|
Unless you draw the UI elements with the theme data yourself, it's either all or nothing for applying visual styles.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Also, if you want the Office 2003 look, there are dozens of third-party controls out there (maybe even some free ones, though you get what you pay for often times). Just google.
There's a couple here on CodeProject as well, although - IMO - I don't think they even come close to Office 2003.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I can call EnableVisualStyle to make contained controls to have visula styles. But for the form itself, e.g. border colors, how do I make that happen?
|
|
|
|
|
I have never done this, but from reading I think it is possible. You can create a manifest file using XML to tell your application to use the operating system's style.
The file is placed in the same directory as your project, and is called myProject.exe.manifest
I don't have a link for it at the moment, but I'm sure information will be readily available using google
Hope it helps
|
|
|
|
|
I'm not really sure. I've never tried a callback with a class method before. You'll just have to try it. If you would, please reply whether or not it works.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi all,
I tried to implement auto -indentation feature in my editor.
using some ideas from codeguru and codeproject .
i did the following code.
The problem is whenver i press "enter" key
the tab is incremented automatically in the next line.
(straight logic .if u see the code u will unerstand)
but i want the following feature :
if() (Enter key)
{ (Enter key)
MessageBox(); (Enter key)
DrawString(..); (Enter Key)
while(i>0) (Enter key)
{ (Enter key)
bool b = false; (Enter key)
} (Enter key)
} (Enter key)
else (Enter key)
{ (Enter key)
MessageBox(); (Enter key)
}
each time when i press "Enter" key the tab position
is changed . How to identify and move the tab
key properly.
Following is the fundamental code which i did .
How to improve this logic further.
I am struck up.Please help me.
Source code :
private void richTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
string temp="";
int indent=0;
if(e.KeyCode == Keys.Enter)
{
// taking previous line
string temp = Convert.ToString(richTextBox1.Lines.GetValue(richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart - 1)));
// GetIndent() is used to count the tabs in the previous line
indent = GetIndent(temp,12);
System.Diagnostics.Trace.WriteLine(indent);
//adding one tab further in the next line
for(int i=0;i
|
|
|
|
|
Hi guys,
First off im after some general help, Im in the wounderful process of learning C#, I have created a screen that I want the user to enter a username and password, this data comes form a access(20000) but i want to make it future proof, i mean at the moment im using access this is fine but I may want to use sql server 2000 to be the backend is their a way i can make switiching over easy in the future.
|
|
|
|
|
You have several options. The way that the .NET Framework is heading is the provider pattern, which is a pretty good system. See a recent article in MSDN - Provider Model Design Pattern and Specification, Part 1[^] - for more information.
A conceptually similar way without all the overhead of the typed class factories is what we currently use in our application.
Basically, you design an abstract class that performs the authentication. Then you extend this class (either in a different project or the same project) with Access-specific functionality. Later, you could extend this base class with SQL-specific functionality. In either case, you read-in a type from your application's .config file as a string (like "MyNamespace.MyAccessAuthClass, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef"). You could, for example, simply store this in the <appSettings> section of your .config file and associate that with a key, like "authenticator". You then get that type, create an instance of it, and cast it to your base class (or interface, whichever you prefer - use a base class if you want to have basic functionality implemented, or use an interface if you want no default implementation of anything):
string type =
ConfigurationSettings.AppSettings["authenticator"];
if (type == null)
type = "MyNamespace.MyAccessAuthClass, MyAssembly, " +
"Version=1.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef"
AuthenticatorBase auth = null;
try
{
Type t = Type.GetType(type);
auth = (AuthenticatorBase)Activator.CreateInstance(t);
}
catch (Exception ex)
{
MessageBox.Show("Could not create the authentication package: " + ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(1);
}
Obviously, the Type string is just an example, and you could use a partial type (namespace + classname, assembly name).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
need stuff about network with c#
thanks
|
|
|
|
|
Maybe you should elaborate on what you are looking for exactly.
Networks is not a very narrow topic.
|
|
|
|
|
System.Net namespace.
Due to technical difficulties my previous signature, "I see dumb people" will be off until further notice. Too many people were thinking I was talking about them...
|
|
|
|
|
I've been writing event handlers for my app. I have an event for a mousedown on the form, the event type is System.Windows.Forms.MouseEventArgs.
Using this event type I can type
e.Button to determine if the left or right mouse button
if i'm writing an event for an picturebox click the type is System.EventArgs. The is no method to determine the mouse button for this type. Using this event, is there any way to determine the mouse button, I want to use an if statement to ensure that only left clicks will allow the event code to change the picture box image and right clicks will do nothing.
Thanks in advance
|
|
|
|
|
Try the MouseDown event of your PictureBox . The event handler receives an argument of type MouseEventArgs .
|
|
|
|
|
Thanks for the reply... I have thought of that, however I don't want a mouse down to change anything... if the user clicks the mouse down on the pic and leaves the bounds of the pic it will still change the image. I would like the image changed only if there is a click. It seems I may have to write a MouseDown MouseUp combination to handle this... Can anyone think of an easier way to deal with this?
|
|
|
|
|
You can use the Control class static properties like MouseButtons, MousePosition and the instance methods PointToClient and PointToScreen.
For additional information refer the msdn documentation.
|
|
|
|
|
I used a MouseDown in combination with a MouseUp and tested to make sure that the mouse position was still inside that bounds of the pictureBox. If anyone else was having trouble with this here is the code:
<br />
private void NowPBox_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
if(e.Button == MouseButtons.Left)<br />
leftClick = true;<br />
}<br />
<br />
private void NowPBox_MouseUp(object sender, MouseEventArgs e)<br />
{<br />
if(leftClick)<br />
{<br />
if(e.X + NowPBox.Left >= NowPBox.Left && e.X + NowPBox.Left <= NowPBox.Right)<br />
{<br />
if(e.Y + NowPBox.Top >= NowPBox.Top && e.Y + NowPBox.Top <= NowPBox.Bottom)<br />
{<br />
if(!NowPBox.PressedState)<br />
{<br />
this.NowPBox.Image = this.NavButtons.Images[2];<br />
NowPBox.PressedState = true;<br />
<br />
if(SkinsBox.PressedState)<br />
{<br />
this.SkinsBox.Image = this.NavButtons.Images[3];<br />
SkinsBox.PressedState = false;<br />
}<br />
<br />
this.panel1.Visible = false;<br />
this.panel2.Visible = true;<br />
}<br />
}<br />
}<br />
}<br />
}<br />
|
|
|
|
|
Hi, I am trying to return a BSTR from a C++ function that takes a single BSTR argument. I am using the ATL type CComBSTR. My C++ function looks as follows:
extern "C" BSTR __stdcall MyStringFunction( BSTR s )<br />
{<br />
std::string str = string((LPSTR)s);<br />
...<br />
...<br />
return CComBSTR(str.c_str());<br />
}
At the moment my C# declaration looks like this:
[DllImport(@"C:\MyDll.dll", CharSet = CharSet.Unicode)]<br />
[return : MarshalAs(UnmanagedType.BStr)] public static extern string MyStringFunction( [MarshalAs(UnmanagedType.BStr)] string s );
I have had varying success with different combinations. When I don't add the MarshalAs attribute to the return string, I get the string back ok, but when it gets large ( a few 1000 characters) , I hit problems. With the current declaration, which according to documentation is correct, I only receive the first two characters.
Does anyone know, or can suggest what the problem with my approach is? I am aware of Unicode/Ansi issues, but as far as I can tell, what I have should work.
Thanks,
Christopher
The bomb lives only as it is falling
|
|
|
|
|
std::string str = string((LPSTR)s); Definitely wrong. You need to actually perform the conversion, not simply try to cast it. Remember that BSTR s are always Unicode on Windows. Either use a std::wstring , or use WideCharToMultiByte to convert it.
Your marshalling looks fine.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thanks for the reply. The cast seems to work fine, I have messagebox pop-ups in the C++ to debug it. The string is actually a comma-delimited string that i convert into an array of longs. This is all to avoid passing arrays through the interop boundary . Anyway, I have changed the c# declaration which wasn't working to this, which does work.
[DllImport(@"C:\MyDll.dll", CharSet = CharSet.Auto)]<br />
[return : MarshalAs(UnmanagedType.BStr)] public static extern string MyStringFunction( [MarshalAs(UnmanagedType.AnsiBStr)] string s );
i.e.: I return a BStr, but pass in an AnsiBstr. This works up to the point where the string grows to around 16384, which is 2^14. At that point, my c# function throws an exception:
Object reference not set to an instance of an object
Is there any limit to the size of string you can pass across the interop boundary?
Christopher
The bomb lives only as it is falling
|
|
|
|
|
"Object reference not set to an instance of an object" usually comes out of a System.NullReferenceException . The CLR may throw a NullReferenceException if any part of the code called takes an access violation SEH exception.
Check your C++ code for possible access violations.
I still think you should fix your C++ code. ANSI BSTR s are extremely esoteric and generally wrong. BSTR should, IMO, be reserved for use in Automation-compliant COM objects, and not used in 'flat' APIs. If you must do this via strings, use the LPCSTR /LPSTR types and MarshalAs(UnmanagedType.LPStr) .
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
hi my dear
how can i set text alignment to justify property?
thanks alot
hassan azizi
|
|
|
|
|
The RichTextBox.SelectionAlignment property (of type HorizontalAlignment ) doesn't not support justification.
However, you can do this by P/Invoking SendMessage and sending the EM_SETPARAFORMAT message with a PARAFORMAT2 structure with the dwMask field set to PFM_ALIGNMENT (0x0008) at least, and the wAlignment set to PFA_JUSTIFY (0x0004). This applies to the whole current paragraph and is only supported in the Rich Edit common control (which is encapsulated by the RichTextBox ) 2.0, which probably shouldn't be a problem on modern Windows OSes on which your application would be running; otherwise, you can always deploy a new common controls library with your product.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi dear stewart
thanks for your reply
may i ask you to wrtie sendmessage methode code for me?
best regards
hassan azizi
|
|
|
|
|
[DllImport("user32.dll")]
private static extern int SendMessage(
IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int msg,
int wParam,
ref PARAMFORMAT2 format); This signature is specifically for your needs. This will marshal things correctly without having to do it yourself. A generic SendMessage declaration would look like:
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(
IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int msg,
IntPtr wParam,
IntPtr lParam); If you're not sure how to do this, you're going to have to learn. Interop with unmanaged code also requires some knowledge with the unmanaged APIs you're dealing with - in this case, the Windows Common Controls.
For instance, you're going to have to declare a managed structure for the unmanaged PARAFORMAT2 structure documented in the Platform SDK for the Windows Common Controls.
Microsoft MVP, Visual C#
My Articles
|
|
|
|