|
First of all your code won't compile
And yes all members of an interface must be public visible to everyone using this interface. But you can restrict them ONLY to explicit interface users:
public interface ITest
{
void TestA();
}
public class Class1 : ITest
{
void ITest.TestA() {}
}
static void Main()
{
Class1 c = new Class1();
c.TestA();
ITest t = c;
t.TestA();
}
|
|
|
|
|
I can't seem to figure out how to get the selected date from a MonthCalendar. The DateTime picker has a value property, but I can't find the same for the MonthCalendar. How do I get the selected date from the MonthCalendar?
Thanks
|
|
|
|
|
hope this helps,
add a dateselected handler and use the eventargst oget teh datetime of the selected data, then just use the datatime properties.
<br />
<br />
private void monthCalendar1_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e)<br />
{<br />
this.textBox1.Text = "Date Selected: Start = " +<br />
e.Start.ToShortDateString() + " : End = " + e.End.ToShortDateString();<br />
}<br />
<br />
regs,
g00fy
|
|
|
|
|
Hi all, I have an application in C++ (unmanaged) that was built to use the IQueryCancelAutoPlay interface and the AllowAutoPlay function to allow the application to determine whether it wants to handle media inserted into the CD/DVD drive or let Windows AutoPlay the media.
See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/ifaces/iquerycancelautoplay/iquerycancelautoplay.asp for details.
I want to create a C# application that would do this very same thing. Unfortunately, I have not been able to find anyone who has done this through Google or MSDN.
Would anyone have an idea of where to start? I.e., any methods of importing/invoking the interface into C# would be great.
Thank you!
C
|
|
|
|
|
I am trying to debug a Form. I set a breakpoint on a method and then started the debugger. Under the debug menu I added a Watch1
window. Then I went into MSDN help-- it says I can get the variables into the watch window by dragging them in. Tried a number of things (drag from class view, from Form, but I can't seem to get anything in. What the heck am I missing here -- thanks a lot....
ps- as you can judge from my post I'm a beginner so go easy.....
|
|
|
|
|
To drag and drop a variable, you first have to select it. Press ctrl (for word selection) and click on it. Then drag it.
In the code you can right click on a variable and add it to the watch.
You can just type the name of the variable in the watch window if everything else fails.
---
b { font-weight: normal; }
|
|
|
|
|
I'm not using an image list so this might not be so easily done, but I'm not sure. I'm making a Word Processor in C# using Visual Studio .NET 2003 Professional. But when I start to use some of the toolbar icons (bitmaps) they have a gray or silver background like the ones for bold, italic, right-align, and so forth. How do I get rid of that background color. Are there any icons like this that are free?
Thanks
|
|
|
|
|
Hi all,
I want to write some windows control by myself. I don't really have any idea how to do that actually. Maybe the easiest way would be combine several existing windows controls into one. Like a textbox, button and a calender. My problem is can any windows control be a potential container??
And also a more difficult problem is if I want to build a totally new windows control, what should I do?? Is using the graphics class the right way to go???
Thanks in advance!!!
Asura
|
|
|
|
|
There are generally two types of visual controls as far as .NET/Windows Forms is concerned. You have the Control, which is not a combination of other controls, but a class (and possible support classes) written with painting code, user input handling code, windows message handling code, etc. Then there is the UserControl, which is a simple form surface without a frame that you can combine multiple, existing controls onto, and which has its own, localized event handling loop.
If you just want to combine existing controls to make a reusable interface with say, a label, textbox, button, and filebrowserdialog, you could create a simple usercontrol that lets you browse for a path. You can create events, properties, and methods for this usercontrol, so you can interact with it and respond to it wherever you use it (i.e., on another form or even another user control).
Writing pure, custom controls is quite a bit more complex. You have to write the whole thing from scratch. That includes drawing every aspect of the visual representation, handling keyboard and mouse input, responding to windows messages, and generating events for when things happen on your control (i.e. the user clicked a certain part of the control, or they double-clicked it). Depending on exactly what kind of control your writing, you may need support classes and collections to store listed data, or if your writing a container control, you have to support child controls and proper placement of those child controls.
Custom controls also don't integrate well into the Visual Studio .NET designer unless you directly code for it. This means properly attributing your code to support he property editor, as well as attributing your code with custom type converters and visual designers. There is also the aspect of data binding for custom controls, which, suffice to say, adds a whole nother layer of complexity.
So, to put all that simply. If you have never written a custom control before, start with UserControls (they are a type of form you can create in VS.NET). Once you learn how to create complex user controls, and learn how to create and handle events from your user controls, you could move on to true custom controls. True custom controls, properly written to support the design time environment, data binding, and support interaction with other code (through properties, methods, and events), can easily take 10 times as much code or more than a UserControl. Writing custom controls is very fun, but pace yourself if you really want to learn them. UserControls are a perfect introduction to the world of custom controls.
|
|
|
|
|
Thank you very much for your article. It's very helpful for me.
Asura
|
|
|
|
|
Glad to be of service. If you have questions, feel free to email me. Writing custom controls is a hobby of mine, and I'm glad to give out tips and tricks.
|
|
|
|
|
Jon Rista is right. You can use winform controls like textboxes for creating your own controls. Just create a child class from the textbox class and add your custom events and members to your class.
|
|
|
|
|
Oh, actually, I spaced out subclassing. You can also derive a class from an existing control, nad augment/add to its functionality, like Heinz said. I still recomment starting with UserControls, but subclasses controls are a good intermediate step between UserControls and full custom controls.
|
|
|
|
|
Hi,
I've done a drag and drop of a sqlDataAdapter and generated a dataset on a second WinForm (Form2) I'm opening as a dialog box. I can bind to it and retrieve results but I get an error when I try to use any BindingContext.Count/Position methods on the dataset. Any help greatly appreciated.
Error: 'Cannot create a child list for field myTable.'
Code Snippet Follows:=======================================
try
{
int iCnt;
iCnt = this.BindingContext[this.dsExtPhyLookup1, "tblExternalPhysicians"].Count;
}
catch(Exception exp)
{
MessageBox.Show(exp.Message.ToString());
}
|
|
|
|
|
hi all,
i need to pass a record between forms. i got it working for now, but i don't think it's right.
1st. form has a read only datagrid bound to a dataset.
2nd. on double-click event, i'm currently looping through col values
3rd. send individual col values to new form.
i don't think this is right (and yes, i'm a newbie) cause if i'm using locale then the value in the col on the grid would be a converted value and not necessarily the value in the dataset right?
how can i pass the record from the dataset to a form (best practice) use a structure?
tia
|
|
|
|
|
I assume you want to transfer the data of the current row or something similar.
One apporach would be to fill a structure or little helper class which you can pass around. Another idea would be to transfer the whole DataRow object (DataTable.Rows[currentRowIndex]).
|
|
|
|
|
excellent, i started down the structure path. thanks for such a quick response!
|
|
|
|
|
I'm trying to read numbers from a TextBox and convert them. Even though I have
a number in the TextBox the compiler can't convert. Which got me thinking about the above question....thanks
|
|
|
|
|
Convert.ToInt32(string value) internally calls Int32.Parse(string s) so it doesn't matter which one you call.
What makes you think it doesn't work? Are you probably trying something like Convert.ToInt32(textbox) instead of Convert.ToInt32(textbox.Text)? Or is the string probably not fitting into an integer?
|
|
|
|
|
toint32 takes 1 arguement
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemConvertClassToInt32Topic13.asp
parse takes 2
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemInt32ClassParseTopic3.asp
i might be missing something, but couldn't you also trap the keypress event and verify your numeric's there?
if(char.IsNumber(e.KeyChar) == false)
e.Handled = true;
|
|
|
|
|
HI all
I need to write two C# program ,
The first one is like a server and second one is the client [both program are in the local Host computer].
In C++ i wrote something like it in COM+ (ATL) and the two program had connecting throw this com.
But in C# i don't how to define my 2 different project to have those connection.
Can someone help me ?
Thanks
|
|
|
|
|
|
Hello gurus,
Given a color, I'd like to know how to calculate the nearest color from the standard list?
For example:
given the color: FFD3D3D3, the function will return FFD7D7D7 which is Color.LightGray
Color clr=new Color(0xd3, 0xd3, 0xd3);<br />
Color nearestColor=GetNearestColor(clr);
will return Color.LightGray to nearestColor
Can anybody help me to solve this?
Thanks in advance.
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
|
I have a project where I need to create a windows .exe by compiling code and linking in some resources. This program thats being generated is somewhat unconventional, and I'll explain how. I'm generating a very simple installer app that embeds referenced .dll files inside it, which are extracted and referenced when the installer app is executed. This works great when the installer app is built with Visual Studio .NET, but it does not work when I compile it myself using a CSharpCodeProvider. The resources are written to a .resource file using a ResourceWriter just prior to compilation of the .exe. I add a custom compiler option to embed the resources. Code follows:
PopupProgress.Display("Compiling Installer...", null, "Compiling", "Creating
compiler...", 3, 1);
// Create code compiler
CSharpCodeProvider provider = new CSharpCodeProvider();
ICodeCompiler compiler = provider.CreateCompiler();
// Create compiler parameters
PopupProgress.Display("Compiling Installer...", null, "Compiling",
"Configuring compiler...", 3, 2);
CompilerParameters cparams = new CompilerParameters();
cparams.Evidence = new
System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence);
cparams.GenerateExecutable = true;
cparams.GenerateInMemory = false;
cparams.IncludeDebugInformation = false;
//cparams.MainClass = "S2CIPInstaller.Main";
//cparams.OutputAssembly = step4.CompileTarget;
cparams.TempFiles = new TempFileCollection(m_basePath + @"temp\", true);
cparams.ReferencedAssemblies.Add("System.dll");
cparams.ReferencedAssemblies.Add("System.Drawing.dll");
cparams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
// cparams.ReferencedAssemblies.Add("System.XML.dll");
cparams.ReferencedAssemblies.Add(m_basePath +
@"temp\SynapticEffect.Collections.dll");
cparams.ReferencedAssemblies.Add(m_basePath + @"temp\DatGen.DBPF.dll");
cparams.CompilerOptions = "/resource:\"" + m_basePath +
"temp\\S2CIPInstaller.resources\"";
//cparams.Win32Resource = m_basePath + @"temp\S2CIPInstaller.resources";
// Compile
PopupProgress.Display("Compiling Installer...", null, "Compiling", "Please wait...", 3, 3);
CompilerResults results = compiler.CompileAssemblyFromSource(cparams, code);
PopupProgress.Remove();
int errCount = 0;
for (int i=0; i<results.errors.count; i++)
{
="" if="" (!results.errors[i].iswarning)
="" errcount++;
}
if="" (errcount=""> 0)
{
MessageBox.Show(this, "There were errors during compilation. Installer not created.");
}
else
{
MessageBox.Show(this, "Installer successfully created!");
}
When I use the code provider from my own program, I get the following error (only visible after attaching with a debugger. I apologize for the coded .exe name --> yodjgmq_.exe):
An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the
specified culture (or the neutral culture) in the given assembly. Make sure "S2CIPInstaller.resources" was correctly embedded or linked into assembly "yodjgmq_". baseName: S2CIPInstaller locationInfo: DatGen.S2CIPInstaller resource file name: S2CIPInstaller.resources assembly: yodjgmq_, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Does anyone know why the installer app works when compiled with VS.NET, but not with the CSharpCodeProvider and ResourceWriter classes from the .NET Framework from my own code? Any insight is greatly appreciated.
Jon Rista
jrista@hotmail.com
|
|
|
|
|