|
This code creates a control (based on the Panel) with a new property named "Colors". Setting the property yo an array of colors will display the colors.
(example:
multiColorPanel1.Colors = new Color[] { Color.Red, Color.White, Color.Blue};
end of example)
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace Project1
{
/// <summary>
/// Summary description for MultiColorPanel.
/// </summary>
public class MultiColorPanel : System.Windows.Forms.Panel
{
private Color[] colors = null;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public MultiColorPanel()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitializeComponent call
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
public Color[] Colors
{
get
{
return colors;
}
set
{
colors = value;
this.Invalidate();
}
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
if ((colors != null) && (colors.Length > 0))
{
Graphics area = pevent.Graphics;
int height = this.Height / colors.Length;
for (int index = 0; index < colors.Length; index++)
{
Rectangle rect = new Rectangle(0, height * index, this.Width, this.Height);
Brush brush = new SolidBrush(colors[index]);
pevent.Graphics.FillRectangle(brush, rect);
}
}
else
{
base.OnPaintBackground (pevent);
}
}
}
}
|
|
|
|
|
How to referenc functions in other code file/unit?
|
|
|
|
|
Thats a bit vague. Are they .NET assemblies or C code or what?
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"Get in touch with your Inner Capitalist - I wish you much success!" -- Christopher Duncan, Lounge 9-Feb-2004
|
|
|
|
|
Sorry, I am new in .Net.
I want to call a functin in c# code file from a form code in same application, I tried this:
//uMyLib.c
// created on 12/02/2004 at 02:16 ?
using System;
namespace TextLib
{
public class TextLib
{
string ReversText(string s)
{
string txt = "";
//for (int i=0; i <= s.Length-1; i++)
for (int i = s.Length-1; i>=0 ;i--)
{
txt += s[i].ToString();
}
return txt;
}
}
}
//==============
// project created on 12/02/2004 at 02:12 Õ
using System;
using System.Windows.Forms;
using uMyLib; // file name
namespace MyFormProject
{
class MainForm : System.Windows.Forms.Form
{
.......
..........
..........
void ButtonClick(object sender, System.EventArgs e)
{
uMyLib.MyLib S = new uMyLib.TextLib();
label.Text = S.ReversText(textBox.Text);
}
Thanks
|
|
|
|
|
klufy wrote:
using uMyLib; // file name
This should not be the name of the file, but the name of the namespace. So rewrite it as:
using TextLib;
Also, is this file in the same project or another project?
If it is in the same project then there is nothing more you should need to do. If it is in another project is the other project in the same solution as this one or not?
If the two projects are in the same solution right click the forms project (which is probably your exe file) and select "Add Reference..." from the context menu, in the dialog select the projects tab and select the project that includes TextLib.
If the project containing TextLib is not in the solution it may be best to add it to the solution (if they are both under your control) or just link to it if not.
To add the other project right-click on the root element in the Solution Explorer (the solution element) and select "Add"-->"Existing Project..." and browse for the project file.
Does this help?
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"Get in touch with your Inner Capitalist - I wish you much success!" -- Christopher Duncan, Lounge 9-Feb-2004
|
|
|
|
|
This is fundamental to object-oriented programming and you really should pick up a good book about the .NET Framework (which most entry-level books present information on basic OO designs and programming) from http://www.microsoft.com/mspress[^] or something.
First of all, the files DO NOT matter, so long as their compiled into the same assembly (except in the case of Java, in which only one public class can be in a file and the classname and filename must match, and they get compiled to .class files). Second, you don't reference assembly names in code - the current assembly references other assemblies. In your case, you're using two completely different namespaces, TextLib and MyFormProject . If these are in the same assembly, they typically should share a common namespace! Notice how you keep typing using System.Something ? That's not magic - you're merely telling the compiler which namespaces - which can span multiple assemblies - to look in for classes and other Types. The filename matters not.
So, you can do either of the following:
using TextLib;
TextLib tl = new TextLib();
label.Text = tl.ReversText(textBox.Text); or
TextLib.TextLib tl = new TextLib.TextLib();
label.Text = tl.ReversText(textbox.Text); Again, you really should read a book or two on .NET programming.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Colin and Heath.
Boath files are in the same project.
My call now is like this:
void ButtonClick(object sender, System.EventArgs e)
{
TextLib.TextLib tl = new TextLib.TextLib();
label.Text = tl.ReverseText(textBox.Text);
}
I got this error :
'TextLib.TextLib.ReverseText(string)' is inaccessible due to its protection level(CS0122)
Thank you again for your advice.
|
|
|
|
|
On your ReverseText Function put it as
public string ReverseText(string s)
{
}
This is because the C# Compiler marks it as private(thus only allowing it to be accessed by the same class it's in)
if you don't specify an access modifier.
Other modifiers are
protected
virtual
abstract
private
public
Look up these modifiers on codeproject for more info =)
------------------
I'm naked under my clothes...
|
|
|
|
|
|
Actually, lookup information on access modifiers here: 3.5.1 Declared Accessibility[^] in the C# language specification on MSDN. In fact, you'd do well to read the whole specification.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi all,
I need your EXPERT opinion on something, I am trying to create an application to track the steps a user took while using an application, (kind of like turbo tax or window xp does) and store it in a database. I then need to be able to display the steps from the database, on a menu or a list, and they have to be links(because each link they will be able to fire off a child window).
My question is what would be the best way to perform these tasks? I am a nebie so bare with me .........I am going to use C# for the application part of it, but how do I store the user steps? And how do I display them? What else do I need to create this app, i.e. XML?ASP? I dont what it to be webbased though, I want it to be a stand alone app. Links to examples would be helpful. As a matter of fact, any help would be appreciated. Thanks in advance.
|
|
|
|
|
Just save the keys and mouse clicks in their respective events.
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
It is, simply put, an event based scenario. Depending on what you want to track, you can use standard events (those offered by the Framework classes) or create your own events to deal with your application's business logic (by building your own event handler delegate classes).
Also, depending on the amount of user data you want to track, you can store it in simple XML files (if the amount is small) or in a more sophisticated data store like an Access or SQL server database (if you want to store large quantities or complex relationships of user data).
|
|
|
|
|
hi;
i've some problems with my SMTP client ...
1) is there a better way to get the mail exchange of a server other than nslookup ???
2) how to send to a a recipient not on this server (i connect- with a socket- to yahoo and i want to send a mail to hotmail) ,or i have to connect to the appropriate server for each reciepient ??
3) when i send data to yahoo the no text appeares on the message. in spite it did on hotmail and others ....
thx alot
Mina Aziz
|
|
|
|
|
mina_aziz wrote:
1) is there a better way to get the mail exchange of a server other than nslookup ???
Programmatically. There is a couple examples of this, including A Managed C++ Email Validator Control for ASP.NET
[^]. It's in Managed C++, but if you truly understand .NET programming, you should have a problem at all translating it to C#.
mina_aziz wrote:
2) how to send to a a recipient not on this server (i connect- with a socket- to yahoo and i want to send a mail to hotmail) ,or i have to connect to the appropriate server for each reciepient ??
No, not unless they allow relaying to other domains, which most SMTP servers don't (that's how SPAM spreads and why should their server be burdened with it). The reason that MX records exist is so that SMTP clients connect to the mail server for a domain. The DNS administrator must make sure that the SMTP servers he sets as the MX records for a domain will relay for that domain.
mina_aziz wrote:
3) when i send data to yahoo the no text appeares on the message. in spite it did on hotmail and others
Without an example, who could tell you what's wrong?! Be more specific. More than likely, you're using an invalid MIME type with a multi-part MIME email. For a simple test, all you need to do is this:
$ telnet mail.domain.com 25
HELO host.mydomain.com
MAIL FROM: username@mydomain.com
RCPT TO: username@domain.com
DATA
Subject: Testing
This is a test
.
QUIT This is the most basic email and if it doesn't work, then Yahoo! has a problem (which I HIGHLY doubt).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Folks,
I'm new to web-based programming. I'm wondering if anyone has recommendations or can point me to info on the following?
I'd like to implement a web-based slider control that is similar to Jens Scheidtmann's CRangeSlider. A cleaner version of what I'd eventually want to build is something like a Spotfire slider. I can rely on an explicit button that will do the postback when the user is ready to submit the range they have selected. On top of the slider's two ends, I'd like to place two text boxes (or equivalents). The text would show the dynamically changing low end and high end range values that the user is selecting with the sliders.
For the gui, do I have to do custom draw here? Can I do this purely as an asp.net control? Or do I have to use JavaScript? I don't have any experience with JS, but it seems trivial enough. But if need to do with JS, how do I do the event handling?
Any help, suggestions, worldly wisdom, chocolate chip cookies?
Thanks
|
|
|
|
|
Flying Iguana wrote:
I'm new to web-based programming.
No kidding!
You can't "owner-draw" in HTML. Web pages are constructed of HTML, images, scripts (like JS), and such. If you need runtime drawing of graphics, you either generate them on the server or use ActiveX (requires Windows and a complicated setup with Wine on linux or BSD and Konquerer, and even then it may still not work), Java (requires a JRE on the system and Java to be enabled, plus it's sandboxed), or .NET smart clients (requires .NET on Winodws, Internet Explorer, and is sandboxed as well).
HTTP - the protocol of the web - is also stateless and essentially one way. The client makes a request and the server returns a response. Period. If you need graphics (like charts and what-not), these must be rendered on the server directly to the response stream using the URL requested, or saved as a file with the path included in HTML.
If you need sliders, you're going to have to use Javascript (or any script, though others aren't supported on various platforms like VBScript). ASP.NET describes server-side controls and processing, which javascript only to support a few features (like client-side validation for IE).
New to Javascript, then read. You can find information about JScript - Microsoft's version of Javascript which is mostly compatible (as a language) - at http://msdn.microsoft.com/library/en-us/script56/html/js56jsoriJScript.asp[^]. Understand that most of what you do when scripting Dynamic HTML (DHTML) pages is that the script language manipulates the Document Object Model (DOM). You can read about that for IE (because each browser supports a subset of the standards while adding their own proprietrary extensions) at http://msdn.microsoft.com/workshop/author/dhtml/dhtml_node_entry.asp[^].
If you want more information this, try the ASP.NET or Web Development forums. This is the C# forum.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i have to print a .pdf file to a HP LaserJet 9000 PCL mfp printer which can print duplex. i am using Acrobat COM object to print, and .net's PrintDocument's PrinterSettings for setting the printer. But it returns
false when i use CanDuplex and does not change the duplex setting when i set PrinterSettings.Duplex. The code can be seen below. does anyone have idea how can i solve this? Or is there are more easy way doing this like using a PrinttoFile printer or etc.?
PrintDocument1.PrinterSettings.PrinterName="HP LaserJet 9000 PCL 6";
if(PrintDocument1.PrinterSettings.CanDuplex)
{ axPdf1.printPages(1,1); PrintDocument1.PrinterSettings.Duplex=System.Drawing.Printing.Duplex.Horizontal;
axPdf1.printPages(2,3);
}
i want to thank Heath Stewart for his assistance at printing pdf files.
|
|
|
|
|
Printer settings are not persisted to the printer (unless you set them on the driver itself using the printer properties). They are passed to the print subsystem along with the document. Since Acrobat controls it's own printing, it will send the settings it wants regardless of what you think you set. You could always call printWithDialog if this still fits your requirements. Otherwise, you might consider checking out the Adobe Acrobat SDK, although it might only be available to Adobe Developers Network (or something like that - maybe that was just Photoshop and Illustrator, though). That might contain additional information about controlling the printing from a client.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
isn't it possible to convert pdf file to PostScript format and then print it? Can this solve my problem?
|
|
|
|
|
And how do you propose to do that? You'll still need something that knows how to print and/or convert PDF files. If your printer supports PostScript, you can print to a file but you'll still need a program to read and print the PDF. That's even if your printer supports PostScript (most HP's do, but they prefer PCL for some stupid reason). And to my knowledge, the printing subsystem that .NET encapsulates (at least in the base class libraries) doesn't support spooling RAW documents (since you'd be sending the PostScript, you don't want the driver to convert it to PostScript). You'd need to find a completely different printing library that can spool RAW (and since most printing libraries are to help you accomplish printing graphics and text, I doubt you're going to find one). You'll be forced to P/Invoke calls on the print server. But that still doesn't solve your problem since you still need something that can read and print PDF files.
If this isn't an automated program, just use printWithDialog on the Acrobat OCX. If this is an automated program, take a look at the Acrobat solutions on Adobe[^]'s web site. They do have a product that can monitor directories and convert to PDF (Distiller, part of the Acrobat application). IIRC, there's also one that can monitor a directory and print the files using options you specify.
If the Acrobat OCX doesn't work for you, there are others, some even written in managed code, such as TallPDF (or something like that - they advertise on CodeProject and supposedly are pretty good).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is anyone aware of a way to turn on the windows text-smoothing for one application (not globally from the control panel) I thought there might be an attribute or something in the SetStyle method but I haven't found anything.
thanks,
JR
|
|
|
|
|
FYI, this OS setting changes the algorithm used to display fonts in the system. It is not an application-specific thing, but a change in the algorithm that affects the entire font subsystem.
If you want text smoothing or ClearType support in your application (like Word, Adobe Acrobat, et. al. have), you'll have to add support for it yourself. SetStyle won't because that controls window styles and is analogous SetWindowLong from the Platform SDK. When creating the underlying window handle, this corresponds to CreateParams that is returned and will be used in the call to CreateWindowEx .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
So then how would I go about adding it myself?
|
|
|
|
|
See the Platform SDK for information on GDI and GDI+. From what I've seen, the .NET base class library doesn't support such a featre. As far as ClearType goes, I'm not sure were you can find resources but the best place to start would probably be http://www.microsoft.com/typography/[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|