|
Is it possible to use a directory picker in c#.net 2003? Or do you have to write it yourself?
Thx in advance
|
|
|
|
|
You mean in .NET 1.1? Use the FolderBrowserDialog class.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
yes thx that's it, works great
i found somthing like this on another site but that was a complete program, this is just 3 lines, a lot better
thx!
|
|
|
|
|
I am trying to raw c++ client for a c# server and am stuck at a very strange point - i have gone through the documentations available but none seem to show an unmanaged c++ client(everyone prefers VB)
so here is my steps:
using System;
using System.Runtime.InteropServices;
namespace InterfaceNETServer
{
public interface INETServer
{
string Sayhi();
}
public class InterfaceNETServer:INETServer
{
public InterfaceNETServer()
{
}
public string Sayhi()
{
return "Hi from Server";
}
}
}
The generated typelib ,as from typelib viewer in ole view
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: InterfaceServer.tlb
[
uuid(21D195E2-ECE9-340D-8CE0-079CDC12FAEF),
version(1.0)
]
library InterfaceNETServer
{
// TLib : // TLib : Common Language Runtime Library : {BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib("mscorlib.tlb");
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("Stdole2.tlb");
// Forward declare all types defined in this typelib
interface INETServer;
interface _InterfaceNETServer;
[
odl,
uuid(1701A141-5AE7-35AE-BD6E-D389EDD66D65),
version(1.0),
dual,
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "InterfaceNETServer.INETServer")
]
interface INETServer : IDispatch {
[id(0x60020000)]
HRESULT Sayhi([out, retval] BSTR* pRetVal);
};
[
uuid(2D31E170-65BD-31DF-A526-90624DD704BB),
version(1.0),
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "InterfaceNETServer.InterfaceNETServer")
]
coclass InterfaceNETServer {
[default] interface _InterfaceNETServer;
interface _Object;
interface INETServer;
};
[
odl,
uuid(DD603E31-4155-3DBE-B1BE-357E3863D3EE),
hidden,
dual,
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "InterfaceNETServer.InterfaceNETServer")
]
interface _InterfaceNETServer : IDispatch {
};
};
and my c++ client
#include <iostream.h>
#include <atlbase.h>
#import <mscorlib.tlb>
#import "..\InterfaceNETServer\bin\Debug\InterfaceServer.tlb" no_namespace named_guids
#include "stdafx.h"
int main(int argc, char* argv[])
{
INETServer * cpi= NULL;
CoInitialize(NULL);
CoUninitialize();
return 0;
}
There is no way i can make the compiler recognize the INETServer interface!!!!!!!!
Compiling...
StdAfx.cpp
Compiling...
CLientforNetInterop.cpp
D:\CSHARP\NETSERVERFORINTEROP\CLientforNetInterop\CLientforNetInterop.cpp(15) : error C2065: 'INETServer' : undeclared identifier
The path to the tlb cannot be worng,as i can open the tlb through 'right click->open document' from within this file.Whats wrong ?
|
|
|
|
|
First thing - always attribute your class and interfaces with the GuidAttribute - among other attributes that are handy such as the InterfaceTypeAttribute - to make sure that the GUIDs are constant and use the COM guidelines: if you need to change your interface after publishing your code, make a new interface that inherits from the original one, called INETServer2 or something, with a new GUID.
As for the actual problem, look at the header file that the compiler generates when it imports the typelib. It should have a .tlh extension, IIRC, and is in your project directory. You might need to add the raw_interfaces_only attribute to your #import statement. The .tlh file should tell you what was imported and what they were called.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the help.
BUt although I see the interface name in the generated .tlh file,it simply refuses to recognize the Interface name while compilation.
I change the #import attributes from 'no_namespace named_guids' to 'raw_interfaces_only',but still getting the same error.
Are there any other sugestions?
can a c++ client (compiled usin VC6.0) not be built against a C# server?
I am also surprised that no literature/tutorial is available for this - there seems to be a definite preference for VB clients in .NET references.
|
|
|
|
|
No, don't get rid of no_namespace named_guids , just add raw_interfaces_only . If you remove no_namespace , then a namespace is defined for which you need to use using namespace theNamespace; after your #import .
A native C++ app can consume a CCW (COM-Callable Wrapper) for managed code. In fact, I do it in my article about Java interop with .NET at the presentation layer, which you could read about and see the example of how I consume a managed COM object from unmanaged code. See http://www.codeproject.com/dotnet/javanet.asp[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The whole message didn't show!!! The config file code were missing!
The config file looks like this:
------------------------------------------------------
app.config
add key="ColorClosed" value="255,0,0"
------------------------------------------------------
I have also tried this:
add key="ColorClosed" value="#FF0000"
|
|
|
|
|
The ColorConverter converts either color names (from the KnownColors enumeration) or hex values with or without the pound (#) sign. That should work when you read the string using AppSettings["ColorClosed"] (no need to call ToString , BTW, since it already is a string and - if it's not in your .config file - would return null thus throwing a NullReferenceException . If you want to store colors using the R,G,B notation, then you'll need to split the strigs, convert them to int s, and use Color.FromArgb , which you seem to be doing.
Since you didn't tell us what the actual problem is (i.e., what Exception is thrown and what the message is), all I can do is guess that your .config file isn't 1) named correct (should be YourAppName.exe.config), and/or 2) isn't in the same directory as the application. The best thing is to step through your code and check the state of each variable. It also helps to split your longer statements into shorter ones - the compiler will do that anyway so there's no loss in performance.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok, a better explenation:
I have made a user control that simple draws a circle and will fill that circle with a color defined in the config file. Then I want to drag this user control out on my main form but when I do this the following error occurs:
"An exception occured while trying to create an instance of xxxx. The excepiton was "ColorConverter cannot convert from (null)"."
The config file is named app.config is in the same directory as the user control and contains
add key="ColorClosed" value="#FF0000"
Now my code looks like this in the user control:
//Declaration of redBrush
SolidBrush redBrush = new SolidBrush((Color)TypeDescriptor.GetConverter(typeof(Color)).ConvertFromString(System.Configuration.ConfigurationSettings.AppSettings["ColorClosed"]));
The method that draws the circle looks like this;
private void CircleControl_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics dc = this.CreateGraphics();
dc.DrawEllipse(blackPen, 0, 0, 40, 40);
if(_status == Switch.Open)
{
dc.DrawRectangle(blackPen, 0, 15, 40, 10);
dc.FillRectangle(greenBrush, 0, 15, 40, 10);
}
else if(_status == Switch.Closed)
{
dc.DrawRectangle(blackPen, 15, 0, 10, 40);
dc.FillRectangle(redBrush, 15, 0, 10, 40);
}
else if(_status == Switch.Intermediate)
{
dc.FillEllipse(yellowBrush, 0, 0, 40, 40);
}
else
{
}
}
|
|
|
|
|
Like I said, the .config file must use the same name as your application (case-insensitive) with .config appended. app.config is not a valid name, which is why you're getting null (which you should be checking anyway - NEVER trust any user input whether directly or indirectly input into your code).
If your application is called MyApp.exe, then your config file must be called MyApp.exe.config. This is documented in the .NET Framework SDK.
If you want, create a new file in your project called App.config (must be an upper-case "A", at least in VS.NET 2002). The project "compiler" will rename this appropriately and will copy it to the target directory for the current build.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm trying to convert a string written in a config file to a System.Drawing.Color and I have tried lots of different solutions but nothing have worked. This is the last shot a had on it:
------------------------------------------------------
app.config
<add key="ColorOpen" value="0,181,0">
------------------------------------------------------
private SolidBrush GetClosed()
{
string strClosed = System.Configuration.ConfigurationSettings.AppSettings["ColorClosed"];
string[] parts =strClosed.Split(',');
int rValue = int.Parse(parts[0]);
int gValue = int.Parse(parts[1]);
int bValue = int.Parse(parts[2]);
Color colorClosed = Color.FromArgb( rValue, gValue, bValue );
SolidBrush redBrush = new SolidBrush(colorClosed);
return redBrush;
}
------------------------------------------------------
I have also tried this:
SolidBrush redBrush = new SolidBrush((Color)TypeDescriptor.GetConverter(typeof(Color)).ConvertFromString(System.Configuration.ConfigurationSettings.AppSettings["ColorClosed"]));
---------------------------------------------------------
and this:
string strOpen = System.Configuration.ConfigurationSettings.AppSettings["ColorOpen"].ToString();
Color colorOpen = (Color)TypeDescriptor.GetConverter(typeof(Color)).ConvertFromString(strOpen);
SolidBrush greenBrush = new SolidBrush(colorOpen);
-----------------------------------------------------------
Please help me!! I'm going creazy over this!
/Anze
|
|
|
|
|
Hi there. How about the ColorTranslator class? Here's a link to the MSDN documentation[^]
using System.Drawing;
Color c = ColorTranslator.FromHtml("#999999");
|
|
|
|
|
I am sorry for My English is poor
i want to ask that
i have a .XSD file which have an complexType
the complexType have some element
can i use fill method to fill these element
study everyday
|
|
|
|
|
i think that you have to use the datareader to fill it up
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
thank you
i will try
study everyday
|
|
|
|
|
It's better to use a DataAdapter .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Don't use a DataReader with a DataSet - you have to handle a lot of code yourself that a DataAdapter already does for you if you establish the table and column mappings either programmatically or - like you seemed to have done - by creating a typed DataSet . If you give your DataAdapter derivative (like the SqlDataAdapter ) at least a SelectCommand , it will fill your typed DataSet correctly (so long as the SQL statement corresponds to the typed DataSet ) when you call DataAdapter.Fill . If you assign the optional properties, DeleteCommand , UpdateCommand , and InsertCommand on the DataAdapter , you can also call Update to update your ADO.NET data source with changes made to your DataSet since you last fill it (or called AcceptChanges , which removes all tracking information for each row).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thank you
i find that i can use fill method
your Suggest is very good for me
my english is poor
so there are maybe some errors with english :;P
study everyday
|
|
|
|
|
I'm wondering how to display tabs or buttons for open documents in a multiple document interface.
For example, lets say there are 5 documents open in the MDI Container, and they are all maximized, there is no way to swap back and forth to the other documents.
What would be the best way to do this?
Thanks in advance,
Jon
|
|
|
|
|
You could add a Menu to the MDI Parent, call it, say, &Window, and set it MDIList property to true.
RageInTheMachine9532
|
|
|
|
|
I have made a windows menu for open windows, but this is not what I am trying to do. I need some kind of tab style control so that users can click on directly to swap back and forth, kinda like all good MDI applications.
|
|
|
|
|
Then you'll need to either create your own form classes and owner-draw these tabs, or use an existing library like Magic Controls which can be found here on CodeProject (along with other implementations). Magic Controls is now a commercial library, but an older, stable version is posted here for the CodeProject community.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have 3 radiobuttons on a form, when i do this in the code:
if ((optWin32.Checked) or (optWin32Unix.Checked))
i get 2 mistakes:
'Lay_out.frmSessions.optWin32' denotes a 'field' where a 'class' was expected<br />
<br />
The name 'or' does not exist in the class or namespace 'Lay_out.frmSessions'
what can i do about it?
thx in advance
|
|
|
|
|
or is not part of the C# language. You should use the boolean operator || instead. See this web site for a list of operators in C#[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event[^].
|
|
|
|
|