|
HTTP status code 500 could be just about anything. That's like just saying, "There's an error". If this is an ASP.NET application, check the trace.axd "file" from your web application's root if logging is enabled from your web application's Web.config file. This should give more information.
I'm not even totally sure if this will work, although I'm fairly positive this will not work if the user doesn't have local login privileges since a Windows station (i.e., support for window and graphic handles) would have to be available (so far as docs read).
If you need more information about how to set up printing, then read the .NET Framework SDK documentation for the related classes, such as PrintDocument , PrinterSettings , etc. That's why it's there.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
Thanks for the reply. I'll definatly give the trace.axd a look. As far as login privaledges go, Im testing on the same machine as I am developing on so that should'nt be an issue. Also, everything I have so far IS from the SDK documentation and has not helped. If I wanted to use forms with button event listeners I am sure that info would be of great use. Like I said, this code works fine in a standard C# project. Thanks again.
|
|
|
|
|
You don't seem to get it. The ASP.NET worker process (aspnet_wp.exe) runs as a particular user, just as IIS runs as a particular user - and it isn't you unless you know how to properly edit the machine.config file (and judging by your comments, I doubt that). In IIS6 (on Windows Server 2003), the application pool runs as a particular user. Again, this isn't you. By default, ASP.NET 1.0 and 1.1 on IIS5 and 5.1 run as the ASPNET local account. Application pools in IIS6 run as NetworkService (NT AUTHORITY\NETWORK SERVICE) by default. These accounts must be granted privileges. It has nothing to do with you, even if you enable impersonation (which executes the thread - not process - under your credentials).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Your right. I dont get it. If I got it I probably would'nt be posting here! But thanks for you're help. I will look at that and see if I can figure it out. Thanks
|
|
|
|
|
No, what you don't seem to get is what I've explained three times in this thread: ASP.NET runs under a particular user's credentials - not yours. Credentials are a username and password. By default, the ASP.NET worker process runs under the local "ASPNET" account. This may not have all the necessary security privileges. You do, but ASP.NET isn't running as you (nor should it - it should be a dedicated, mostly unpriviledged account). The reason this works for you in Windows Forms and not for the ASP.NET application is because your account has a Windows station associated with it - hence all the windows and graphic UI you see. ASP.NET doesn't, unless you set your machine up correctly to do so. This has absolutely nothing to do with C# or .NET.
There are also examples out there. I simplied googled for "ASP.NET PrintDocument" and found several.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have a problem in GDI+, I put a code snippet (draws a rectangle with a text inside) in the onpaint event handler of my simple form but when I resize the form, the handler redraws my rectangle? Is there a way to determine if there is a rectangle or some other thing on the form's drawing area to not to redraw the rectangle? How can I solve this problem? (my code is below...)
Thanks in advance...
Cem Louis
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace GDI_Test01
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.form1_Paint);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void form1_Paint(object sender, PaintEventArgs e)
{
// Obtain the Graphics object
Graphics g = this.CreateGraphics();
int rect_width = 110; int rect_height = 20;
Rectangle rect = new Rectangle((this.Width-rect_width)/2,20,rect_width,rect_height);
FontFamily verdanaFamily = new FontFamily("Verdana");
Font verdanaFont = new Font(verdanaFamily, 12, FontStyle.Bold);
StringFormat strFormat1 = new StringFormat();
strFormat1.Alignment = StringAlignment.Center;
strFormat1.LineAlignment = StringAlignment.Center;
strFormat1.Trimming = StringTrimming.Character;
// Draw text using DrawString
g.DrawRectangle(new Pen(Color.Black), rect);
g.DrawString("GDI+", verdanaFont, new SolidBrush(Color.Red), rect, strFormat1);
verdanaFont.Dispose();
g.Dispose();
}
}
}
|
|
|
|
|
A couple of things.
First, the problem is not that the rectangle is being drawn again when the form is resized, it's that the old one is not being erased.
To solve this use the Graphics object passed into the paint event handler (e.Graphics) instead of creating a Graphics object.
Next, I think you actually do want the rectangle redrawn when your form is resized, so you'll need to add the line ResizeRedraw = true; to your form's constructor. You can see for yourself the difference this makes.
One last thing, since you're doing this painting in the form itself, you can override the OnPaint method rather than handling the paint event.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Hi Charlie,
Thank you for your reply, I didn't know the ResizeRedraw property before.
Regards,
Cem Louis
|
|
|
|
|
Hi.
Can someone show me how to fill 50% of the below drawing with a solid color.
From buttom to top.
Thanks
Regards r9
The drawing:
private System.Drawing.Graphics graphicsObj = null;
private System.Drawing.Pen penBlackWidth1 = new System.Drawing.Pen(System.Drawing.Color.Black,1);
private Point[] curvePoints = null;
private SolidBrush lightGrayBrush = new SolidBrush(Color.LightGray);
private Point point1;
private Point point2;
private Point point3;
private Point point4;
private SolidBrush blackBrush = new SolidBrush(Color.Black);
...................................................
try
{
graphicsObj = e.Graphics;
graphicsObj.DrawLine(penBlackWidth1, 45, 20, 175, 20);
graphicsObj.DrawLine(penBlackWidth1, 45, 20, 45, 120);
graphicsObj.DrawLine(penBlackWidth1, 175, 20, 175, 120);
graphicsObj.DrawLine(penBlackWidth1, 45,120,90,160);
graphicsObj.DrawLine(penBlackWidth1, 175, 120, 135, 160);
graphicsObj.DrawLine(penBlackWidth1, 90, 160, 135, 160);
graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335);
graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335);
graphicsObj.DrawLine(penBlackWidth1, 465, 335, 490, 335);
graphicsObj.DrawLine(penBlackWidth1, 580, 335, 605, 335);
graphicsObj.DrawLine(penBlackWidth1, 473, 345, 483, 345);
graphicsObj.DrawLine(penBlackWidth1, 473, 345, 478, 335);
graphicsObj.DrawLine(penBlackWidth1, 483, 345, 478, 335);
graphicsObj.DrawLine(penBlackWidth1, 587, 345, 597, 345);
graphicsObj.DrawLine(penBlackWidth1, 587, 345, 592, 335);
graphicsObj.DrawLine(penBlackWidth1, 597, 345, 592, 335);
point1 = new Point(592,335);
point2 = new Point(597,345);
point3 = new Point(587,345);
point4 = new Point(592,335);
curvePoints = new Point[]
{
point1,point2, point3, point4
};
graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate);
point1 = new Point(478,335);
point2 = new Point(483,345);
point3 = new Point(473,345);
point4 = new Point(478,335);
curvePoints = new Point[]
{
point1,point2, point3, point4
};
graphicsObj.FillPolygon(blackBrush, curvePoints, FillMode.Alternate);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
|
|
|
|
|
Here's a though - look in your mathematics book. If you want exactly 50%, then find the algorithm given specified polygram. This is a forum for C#, not math.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath Stewart
The algorithm is not the problem.
But how do I fill the figure?
(the C# GDI+ code is my problem)
Regards
C#
|
|
|
|
|
Looking at the Graphics class, the logical choices are FillPolygon , FillPath , or FillRegion . Full class documentation - it's a great thing to read.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
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).
|
|
|
|
|