|
hi
I need to print text but the font height has to be configurable.
I know I can change the font size at run time, but changing the font size changes both height and width proportioally.
For example I need to increase the witdh X2 ,and the height X 4.
Thanks!
|
|
|
|
|
Fonts are graphical representation of characters and are designed to resize proportionally. If you need to resize them disproportionately, then you'll need to transform them.
One way would be to either create a new Graphics device or to adjust your math - if possible - to account for the transformation you'll be performing to the Graphics object.
To perform the transformation, you can use a myriad of methods on the Graphics class - all documented in the .NET Framework SDK. One such method follows:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
Test()
{
StretchLabel lbl = new StretchLabel();
Controls.Add(lbl);
lbl.Dock = DockStyle.Fill;
lbl.ScaleHeight = 4f;
lbl.Font = new Font(Font.FontFamily, 20f);
lbl.ScaleWidth = 2f;
lbl.Text = "Sample";
Text = "Sample";
}
}
class StretchLabel : Label
{
SizeF size = SizeF.Empty;
float scaleWidth = 1f;
float scaleHeight = 1f;
[DefaultValue(1f)]
public float ScaleWidth
{
get { return scaleWidth; }
set { scaleWidth = value; }
}
[DefaultValue(1f)]
public float ScaleHeight
{
get { return scaleHeight; }
set { scaleHeight = value; }
}
protected override void OnTextChanged(EventArgs e)
{
using (Graphics g = CreateGraphics())
size = g.MeasureString(Text, Font, (SizeF)Size);
base.OnTextChanged(e);
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.ScaleTransform(scaleWidth, scaleHeight, MatrixOrder.Append);
g.DrawString(Text, Font, new SolidBrush(ForeColor), PointF.Empty);
base.OnPaint(e);
}
} Pay close attention to the Graphics.ScaleTransform , which I recommend reading about in the .NET Framework SDK.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
|
I think I got it to do what I want. Here is the code
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
namespace FontSizeTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtH;
private System.Windows.Forms.TextBox txtW;
private System.Windows.Forms.TextBox txtStr;
private System.Windows.Forms.Button btnGo;
private System.Windows.Forms.PictureBox pictureBox1;
private System.ComponentModel.IContainer components;
public Form1()
{
InitializeComponent();
}
/// <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 Windows Form 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()
{
this.components = new System.ComponentModel.Container();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.panel2 = new System.Windows.Forms.Panel();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.txtH = new System.Windows.Forms.TextBox();
this.txtW = new System.Windows.Forms.TextBox();
this.txtStr = new System.Windows.Forms.TextBox();
this.btnGo = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// notifyIcon1
//
this.notifyIcon1.Text = "notifyIcon1";
this.notifyIcon1.Visible = true;
//
// panel2
//
this.panel2.Controls.Add(this.label2);
this.panel2.Controls.Add(this.label1);
this.panel2.Controls.Add(this.txtH);
this.panel2.Controls.Add(this.txtW);
this.panel2.Controls.Add(this.txtStr);
this.panel2.Controls.Add(this.btnGo);
this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location = new System.Drawing.Point(0, 165);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(336, 80);
this.panel2.TabIndex = 12;
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label2.Location = new System.Drawing.Point(164, 30);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(128, 16);
this.label2.TabIndex = 16;
this.label2.Text = "Height (Millimeters)";
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label1.Location = new System.Drawing.Point(20, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(128, 16);
this.label1.TabIndex = 15;
this.label1.Text = "Width (Millimeters)";
//
// txtH
//
this.txtH.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtH.Location = new System.Drawing.Point(164, 54);
this.txtH.Name = "txtH";
this.txtH.Size = new System.Drawing.Size(64, 20);
this.txtH.TabIndex = 14;
this.txtH.Text = "15.00";
//
// txtW
//
this.txtW.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtW.Location = new System.Drawing.Point(20, 54);
this.txtW.Name = "txtW";
this.txtW.Size = new System.Drawing.Size(64, 20);
this.txtW.TabIndex = 13;
this.txtW.Text = "80.00";
//
// txtStr
//
this.txtStr.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtStr.Location = new System.Drawing.Point(20, 6);
this.txtStr.Name = "txtStr";
this.txtStr.Size = new System.Drawing.Size(268, 20);
this.txtStr.TabIndex = 12;
this.txtStr.Text = "This is the test string. change it or the box size";
//
// btnGo
//
this.btnGo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnGo.Location = new System.Drawing.Point(288, 40);
this.btnGo.Name = "btnGo";
this.btnGo.Size = new System.Drawing.Size(48, 32);
this.btnGo.TabIndex = 11;
this.btnGo.Text = "&Go";
this.btnGo.Click += new System.EventHandler(this.btnGo_Click);
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.White;
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(336, 165);
this.pictureBox1.TabIndex = 13;
this.pictureBox1.TabStop = false;
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(336, 245);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.panel2);
this.Name = "Form1";
this.Text = "Form1";
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
void PrintScale(
Graphics gfx,
float widthMM, float heightMM, string text,
Brush color, float xMM, float yMM)
{
xMM /= widthMM;
yMM /= heightMM;
gfx.ScaleTransform(widthMM, heightMM, MatrixOrder.Append);
gfx.DrawString(text, new Font(Font.FontFamily, 1),color,xMM,yMM);
//restore
gfx.ScaleTransform(1/widthMM, 1/heightMM);//, MatrixOrder.Append);
}
void DoPaint2 (System.Windows.Forms.PaintEventArgs e)
{
SizeF sz;
string str5 = txtStr.Text;
int strLen = str5.Length;
float boxW=float.Parse(txtW.Text), boxH=float.Parse(txtH.Text);
float charW, charH;
float scaleX, scaleY;
Pen pen ;
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
sz = e.Graphics.MeasureString(str5,new Font(Font.FontFamily,1)); //Find string length using font of size 1
charH = sz.Height; // character height
charW = sz.Width / strLen; // avg. character width
scaleY = boxH / charH;
scaleX = (boxW/strLen) / charW;
pen = new Pen(Brushes.Red,0.2f);
e.Graphics.DrawRectangle(pen, 5f,5f,boxW,boxH);
PrintScale(e.Graphics,scaleX,scaleY,str5, Brushes.Black,5f,5f);
}
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
try
{
DoPaint2 (e);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnGo_Click(object sender, System.EventArgs e)
{
pictureBox1.Refresh();
}
}
}
|
|
|
|
|
Hi,
I was making a very simple windows application in C#. the application runs fine when i create a new windows application but when i add a button on the form a problem occurs. Although the application compiles correctly, but when i run the application it gives an exception saying,
"An unhandled exception of type 'System.ArithmeticException' occurred in system.drawing.dll
Additional information: Overflow or underflow in the arithmetic operation."
I am really confused here because i am placing the button on the form using the form designer. i have not even touched the code itself. i also tried to add the button to the form by coding myself but the same problem exists.
please help me i will be really thankful.
bye.
|
|
|
|
|
Try changing your code to the following and seeing if it helps any:
[DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)]<br />
public static extern int _controlfp(int n, int mask);<br />
<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
_controlfp(_CW_DEFAULT, 0xfffff);<br />
Application.Run(new Form1());<br />
}
|
|
|
|
|
Something is really weird. What does the code that gets added look like ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hello!
I've used C# and .NET for about a year and i would need some help with books to buy. I need some good books in OOP thinking (not syntax and such, but tips about different approaches to different problems). And also visual c# books that are above beginner level. I would really like the books to be in project-form, meaning it takes you through the stages of several smaller applications/projects.
So if anyone has any tips i would appreciate it!
Thanks!
|
|
|
|
|
Programming Windows with C#
http://www.amazon.com/exec/obidos/tg/detail/-/0735613702/qid=1095869556/sr=1-3/ref=sr_1_3/104-9011139-0631159?v=glance&s=books
A really good windows forms programming book.
Applied Microsoft .NET Framework Programming
http://www.amazon.com/exec/obidos/tg/detail/-/0735614229/qid=1095869620/sr=1-2/ref=sr_1_2/104-9011139-0631159?v=glance&s=books
This one is about .net framework. Highly recommended.
Design Patterns C#
http://www.amazon.com/exec/obidos/tg/detail/-/0321126971/qid=1095869705/sr=1-1/ref=sr_1_1/104-9011139-0631159?v=glance&s=books
This one is more about software design (using patterns). Good stuff on OOP thinking.
|
|
|
|
|
Hi
How can get the information about folders and files on a web server in C#. I want to create a application that will download folders and files from web server.
Regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
Unless the web server is specifically setup to allow you to get the list of files and folders, you're sunk. Now-a-days, for security reasons, 95% of them DON'T let you see this stuff. You'll have to do this using FTP if the site has an FTP server pointed at the same pages.
You could write a web page scraper that would follow and download the files for every link in each page and download every file, keeping track of which directory these files come from on the web server.
But, then again, this has been done many time over. A good example of this kind of work is BlackWidow[^] by Softbyte Labs.
Sites have even developed countermeasures for rippers like this too. Noone wants all of their copyrighted content taken from them without they're permission, now do they?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Another example is Flashget Site explorer feature
|
|
|
|
|
In addition to using FTP like Dave mentioned, you could also try DAV but this isn't not implemented on a majority of servers and is typically authorized only to authenticated users.
A web crawler (not scraper, which grabs content from a page instead of crawling the links like a web crawler) would suffice. Keep a collection of directories and files and do NOT follow <FORM> actions. You're in a world of trouble if you do, and could be held liable for damages (not to mention more difficult parsing is often involved).
But Dave's right; there are serious legal concerns for crawling and caching certain content, much more in the last few years than when the Web first started. Besides, as Dave and the other reply pointed out there's already many programs that do this. Why developer yet another?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi all,
Thanks for your suggestions.
In fact I am new to web programing. I was wondering if we could download through the browser then why not through myown application.
I just want to avoid the windows progress bar while downloading. And also specify certain urls and forget about it. These will be automatically downloaded to the specified folder. Cool ! right ?
Thanks again
Regards
Shiraz
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
Downloading has nothing to do with the "browser". You download things from web sites - or just about any remote machine through TCP/IP via sockets.
You can download files without any progress at all. Read about the WebRequest and WebResponse classes, as well as their derivatives like HttpWebRequest and HttpWebResponse . You can also use the easy-to-use WebClient class to download files.
All these classes includes examples in the .NET Framework SDK which was installed with Visual Studio .NET or standalone, however you obtained it. We have also discussed this many times in the past on this forum, so if you want to learn more, click "Search comments" above, but you should read the .NET Framework SDK documentation for those classes and their members first.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
My application goes throught multiple database access.
during this time, the application is frozen since all its resources are dedicated to the task at hand.
Can anyone tell me how, or preferably point me to a tutorial that would explain to me how to connect to a database without freezing the main application screen?
Thanks in advance,
Jon G
www.Gizmocoder.com
|
|
|
|
|
You need to check into threading, this way you can execute your heavy processing on a separate thread from the main UI thread. I'd recommend you start with the Threading Tutorial[^] from the C# Programmer's Reference.
- Nick Parker My Blog | My Articles
|
|
|
|
|
|
Hi All,
I have created a class that simulates a MDI form by putting the 'child' inside a panel located in the 'parent' form. I had to do this because we use a custom UI that doesn't work properly with standard MDI forms.
The constructor of the class is something like
SemiMDI(System.Windows.Forms.Form client,System.Windows.Forms.Panel parentArea)
So far I've managed to create the form in the designed area and it works ok. Now the problem is when the parent form's resize event is triggered. I know it could be possible to resize the child by calling a 'rearrange' method in my class, but I would like to do it by subscribing the SemiMDI class to the 'resize method of the parent, so everytime I use my class I dont have to worry about linking the child form to the resize event of the parent.
Any ideas? Subscribing events is what I thought, but I'd like to know if you have a better solution.
Thanks!
|
|
|
|
|
In order to attach a handler, you would have to cast client to your Form type and make sure the handler is accessible (i.e., not private - use internal , perhaps).
When handling events in controls and forms, however, it's better to override the event handlers that are already present. So, if you needed to handle the Resize , it's better to override OnResize :
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
} This has less overhead and gives you a greater amount of control over what happens when an event is fired (because your override is actually called before firing the event; calling base.OnEventName is what eventually may fire the event).
With this in mind, you might consider extending all your MDI child forms from a single class that implements this resizing behavior. That would be a good object-oriented design.
Even if this single base class must delegate resizing code to its MDI parent (perhaps the MDI parent contains information that the MDI children can't access), you must still make sure that the handler is accessible and implementing this code in a single base class makes for a better OO design.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thanks. Its fixed and working now
|
|
|
|
|
Hi All,
I have created a class that simulates a MDI form by putting the 'child' inside a panel located in the 'parent' form. I had to do this because we use a custom UI that doesn't work properly with standard MDI forms.
The constructor of the class is something like
SemiMDI(System.Windows.Forms.Form client,System.Windows.Forms.Panel parentArea)
So far I've managed to create the form in the designed area and it works ok. Now the problem is when the parent form's resize event is triggered. I know it could be possible to resize the child by calling a 'rearrange' method in my class, but I would like to do it by subscribing the SemiMDI class to the 'resize method of the parent, so everytime I use my class I dont have to worry about linking the child form to the resize event of the parent.
Any ideas? Subscribing events is what I thought, but I'd like to know if you have a better solution.
Thanks!
|
|
|
|
|
DataSet ds = GetValues("tbl_Users_StoreID");
ddlStores.DataBind();
This I cannot do.
Because GetValues if of type SqlDataReader
and the ddlStores databind() also?
Here is the new code.
But nothing gets populated.
<br />
<%@ import namespace="System.Data" %> <br />
<%@ import namespace="System.Data.SqlClient" %> <br />
<%@ import namespace="System.Text" %> <br />
<%@ Register TagPrefix="mspos" TagName="footer" Src="~/Engine/Controls/footer.ascx" %> <br />
<%@ Register TagPrefix="uc1" TagName="header" Src="Engine/Controls/header.ascx" %> <br />
<br />
<HEAD> <br />
<title>Users Interface to Managing Adminitrators</title> <br />
<meta content="True" name="vs_snapToGrid"> <br />
<script language="C#" runat="server"> <br />
<br />
private DataSet ddlDataSet1 = new DataSet(); <br />
private DataSet ddlDataSet2 = new DataSet(); <br />
private DataSet ddlDataSet3 = new DataSet(); <br />
private SqlConnection myConnection = new SqlConnection("server=(local);database=MSPOS;uid=sa;pwd="); <br />
<br />
<br />
protected void Page_Load(object sender, System.EventArgs e) <br />
{ <br />
if (!Page.IsPostBack) <br />
{ <br />
BindData(); <br />
<br />
} <br />
} <br />
<br />
<br />
<br />
<br />
<br />
private DataSet GetStores() <br />
{ <br />
const string strSQLDDL = @"SELECT StoreID, Store FROM tbl_Users_StoreID ORDER BY Store"; <br />
SqlDataAdapter myDataAdapter = new SqlDataAdapter(strSQLDDL, myConnection); <br />
myDataAdapter.Fill(ddlDataSet1, "ddlStores"); <br />
return ddlDataSet1; <br />
} <br />
<br />
<br />
<br />
private DataSet GetAccessLevels() <br />
{ <br />
const string strSQLDDL = @"SELECT t.AccessLevelID, p.AccessLevel From tbl_Users t Inner JOIN tbl_Users_AccessLevelID p ON t.AccessLevelID = p.AccessLevelID ORDER BY UserName"; <br />
SqlDataAdapter myDataAdapter = new SqlDataAdapter(strSQLDDL, myConnection); <br />
myDataAdapter.Fill(ddlDataSet2, "ddlAccessLevels"); <br />
return ddlDataSet2; <br />
} <br />
<br />
<br />
private DataSet GetReportTos() <br />
{ <br />
const string strSQLDDL = @"SELECT ReportToID, UserName From tbl_Users Where ReportToID = UserID"; <br />
SqlDataAdapter myDataAdapter = new SqlDataAdapter(strSQLDDL, myConnection); <br />
myDataAdapter.Fill(ddlDataSet3, "ddlReportTos"); <br />
return ddlDataSet3; <br />
} <br />
<br />
<br />
private void DataGridUserManagementID_SelectedIndexChanged(object sender, System.EventArgs e) <br />
{ <br />
} <br />
<br />
<br />
<br />
protected void SelectedIndexChangedEventHandler(object sender, System.EventArgs e) <br />
{ <br />
DropDownList ddl=(DropDownList)sender; <br />
DataGridItem dgi=(DataGridItem)ddl.Parent.Parent; <br />
} <br />
<br />
<br />
private void UpdateDB(string cmd) <br />
{ <br />
myConnection.Open( ; <br />
<br />
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand( ; <br />
command.Connection = myConnection; <br />
command.CommandText = cmd; <br />
command.ExecuteNonQuery( ; <br />
} <br />
<br />
<br />
<br />
<br />
private void BindData() <br />
{ <br />
<br />
<br />
string connectionString = "server=(local);uid=sa;pwd=;database=MSPOS"; <br />
System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectionString); <br />
<br />
<br />
<br />
string commandString = "SELECT t.UserID, p.Store, pe.AccessLevel, t.UserName, t.FullName, t.ReportToID From tbl_Users t INNER JOIN tbl_Users_StoreID p ON t.StoreID = p.StoreID INNER JOIN tbl_Users_AccessLevelID pe ON t.AccessLevelID = pe.AccessLevelID ORDER BY UserName"; <br />
<br />
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(); <br />
command.CommandText = commandString; <br />
command.Connection = connection; <br />
connection.Open(); <br />
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); <br />
DataGridUserManagementID.DataSource=reader; <br />
DataGridUserManagementID.DataBind(); <br />
<br />
} <br />
<br />
<br />
<br />
private void DataGridUserManagementID_ItemDataBound(object sender, <br />
System.Web.UI.WebControls.DataGridItemEventArgs e) <br />
{ <br />
<br />
if(e.Item.ItemType == ListItemType.EditItem) <br />
{ <br />
<br />
<br />
<br />
} <br />
<br />
} <br />
<br />
<br />
private void DataGridUserManagementID_Edit(object source, <br />
System.Web.UI.WebControls.DataGridCommandEventArgs e) <br />
{ <br />
DataGridUserManagementID.EditItemIndex = e.Item.ItemIndex; <br />
BindData(); <br />
DataGridUserManagementID.ShowFooter = false; <br />
} <br />
<br />
<br />
private void DataGridUserManagementID_Cancel(object source,System.Web.UI.WebControls.DataGridCommandEventArgs e) <br />
{ <br />
DataGridUserManagementID.EditItemIndex = -1; <br />
BindData(); <br />
DataGridUserManagementID.ShowFooter = true; <br />
<br />
} <br />
<br />
<br />
protected void GridDropDown_SelectedIndexChanged(object sender, EventArgs e) <br />
{ <br />
} <br />
<br />
<br />
private void DataGridUserManagementID_ItemDataBound(object source,System.Web.UI.WebControls.DataGridCommandEventArgs e) <br />
{ <br />
Response.Write("The ItemDataBound Command has been fired"); <br />
<br />
if(e.Item.ItemType == ListItemType.EditItem) <br />
{ <br />
<br />
<br />
} <br />
<br />
<br />
<br />
} <br />
<br />
<br />
private int ExecuteQuery(string sqlCmd) <br />
{ <br />
string connectionString = "server=(local); uid=sa;pwd=;database=MSPOS"; <br />
System.Data.SqlClient.SqlConnection connection =new System.Data.SqlClient.SqlConnection(connectionString); <br />
connection.Open( ; <br />
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand( ; <br />
command.CommandText = sqlCmd; <br />
command.Connection = connection; <br />
return command.ExecuteNonQuery( ; <br />
} <br />
<br />
private void DataGridUserManagementID_Update(object source,System.Web.UI.WebControls.DataGridCommandEventArgs e) <br />
{ <br />
string strUserID; <br />
string strStoreID, strStore; <br />
string strAccessLevelID, strAccessLevel; <br />
string strReportToID, strReportTo; <br />
string strUserName, strFullName; <br />
strUserID = ((Label)e.Item.FindControl("lblUserID")).Text; <br />
<br />
strStoreID = ((DropDownList)(e.Item.FindControl("ddlStores"))).SelectedItem.Value; <br />
strStore = ((DropDownList)(e.Item.FindControl("ddlStores"))).SelectedItem.Text; <br />
strAccessLevelID = ((DropDownList)(e.Item.FindControl("ddlAccessLevels"))).SelectedItem.Value; <br />
strAccessLevel = ((DropDownList)(e.Item.FindControl("ddlAccessLevels"))).SelectedItem.Text; <br />
<br />
strReportToID = ((DropDownList)(e.Item.FindControl("ddlReportTos"))).SelectedItem.Value; <br />
strReportTo = ((DropDownList)(e.Item.FindControl("ddlReportTos"))).SelectedItem.Text; <br />
strUserName = ((TextBox)e.Item.FindControl("editUserName")).Text; <br />
strFullName = ((TextBox)e.Item.FindControl("editFullName")).Text; <br />
Response.Write (strUserName + strReportTo); <br />
if ((strUserName.Equals(strReportTo))) <br />
{ strReportToID = strUserID; <br />
Response.Write ("Strings are Equal"); <br />
} <br />
string cmd="Update tbl_Users Set UserName='"+ strUserName +"', StoreID='"+ strStoreID +"', FullName='"+ strFullName +"', AccessLevelID='"+ strAccessLevelID +"', ReportToID='"+ strReportToID +"' Where UserID = "+ strUserID +""; <br />
ExecuteQuery(cmd); <br />
<br />
DataGridUserManagementID.EditItemIndex = -1; <br />
BindData( ; <br />
<br />
} <br />
<br />
<br />
public void DataGridUserManagementID_Delete(object source, <br />
System.Web.UI.WebControls.DataGridCommandEventArgs e) <br />
{ <br />
<br />
string cmd = "Delete from tbl_Users where UserID = " + DataGridUserManagementID.DataKeys[e.Item.ItemIndex]; <br />
int rowsDeleted = ExecuteQuery(cmd); <br />
<br />
DataGridUserManagementID.EditItemIndex = -1; <br />
BindData( ; <br />
} <br />
<br />
<br />
protected void lstItems_SelectedIndexChanged(object sender, System.EventArgs e) <br />
{ <br />
System.Web.UI.WebControls.DropDownList lst = <br />
(System.Web.UI.WebControls.DropDownList)sender; <br />
DataGridItem dgi = lst.Parent.Parent as DataGridItem; <br />
<br />
if(dgi != null) <br />
{ <br />
Response.Write("<br>ItemIndex: " + dgi.ItemIndex ); <br />
Response.Write("<br>Cells Count: " + dgi.Cells.Count); <br />
} <br />
<br />
} <br />
<br />
<br />
protected int GetSelectedIndex(string StoreID) <br />
{ <br />
int iLoop; <br />
DataTable dt = ddlDataSet1.Tables["ddlStores"]; <br />
for (iLoop=0; iLoop < dt.Rows.Count - 1; iLoop++) <br />
{ <br />
if (StoreID.Equals(dt.Rows[iLoop]["StoreID"].ToString())) <br />
return iLoop; <br />
}; <br />
return 0; <br />
<br />
} <br />
<br />
<br />
private SqlDataReader GetValues(string tableName) <br />
{ <br />
string connectionString = "server=(local);uid=sa;pwd=;database=MSPOS"; <br />
<br />
System.Data.SqlClient.SqlConnection connection = <br />
new System.Data.SqlClient.SqlConnection(connectionString); <br />
connection.Open( ; <br />
<br />
string commandString = "Select * from " + tableName; <br />
<br />
System.Data.SqlClient.SqlCommand command = <br />
new System.Data.SqlClient.SqlCommand( ; <br />
command.CommandText = commandString; <br />
command.Connection = connection; <br />
<br />
return command.ExecuteReader(CommandBehavior.CloseConnection); <br />
} <br />
<br />
</script> <br />
</HEAD> <br />
<body background="images/bg.gif" leftMargin="0" topMargin="0" marginheigh="0" marginwidth="0" <br />
bgColor="#fef9e9"> <br />
<uc1:header id="Header1" runat="server"></uc1:header> <br />
<form id="form1" runat="server"> <br />
<TABLE height="521" cellSpacing="0" cellPadding="0" width="742" border="0" ms_2d_layout="TRUE"> <br />
<TR vAlign="top"> <br />
<TD width="40" height="29"> <br />
<!-- Include start of header --------------------------------------------></TD> <br />
<TD width="702" height="29"> <br />
</TD> <br />
</TR> <br />
<TR vAlign="top"> <br />
<TD height="409"></TD> <br />
<TD><asp:datagrid id="DataGridUserManagementID" runat="server" OnUpdateCommand="DataGridUserManagementID_Update" <br />
OnEditCommand="DataGridUserManagementID_Edit" OnSelectedIndexChanged="DataGridUserManagementID_SelectedIndexChanged" <br />
AllowPaging="True" OnPreRender="DataGridUserManagementID_SelectedIndexChanged" OnItemDataBound="DataGridUserManagementID_ItemDataBound" AllowCustomPaging="True" <br />
AutoGenerateColumns="False" GridLines="None" BorderStyle="Solid" BorderColor="Black" BorderWidth="1px" <br />
CellPadding="2" CellSpacing="2" font-names="arial" font-size="X-Small" HorizontalAlign="Center" <br />
Width="700px"> <br />
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle> <br />
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle> <br />
<AlternatingItemStyle BackColor="PaleGoldenrod"></AlternatingItemStyle> <br />
<ItemStyle BackColor="Beige"></ItemStyle> <br />
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#954896"></HeaderStyle> <br />
<Columns> <br />
<br />
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="<img src=../images/Ok.gif border=0 align=absmiddle alt='Save changes'>" <br />
CancelText="<img src=../images/Cancel.gif border=0 align=absmiddle alt='Cancel editing'>" EditText="<img src=../images/Edit.gif border=0 align=absmiddle alt='Edit this item'>"> <br />
<ItemStyle HorizontalAlign="Center" BackColor="Yellow"></ItemStyle> <br />
</asp:EditCommandColumn> <br />
<asp:TemplateColumn HeaderText="ID"> <br />
<ItemTemplate> <br />
<asp:Label Text='<%# Convert.ToString(DataBinder.Eval(Container.DataItem, "UserID")) %>' BackColor="lightblue" Font-Bold="true" Runat="server" ID="lblUserID"> <br />
</asp:Label> <br />
</ItemTemplate> <br />
</asp:TemplateColumn> <br />
<asp:TemplateColumn HeaderText="Store"> <br />
<ItemTemplate> <br />
<%# Convert.ToString(DataBinder.Eval(Container.DataItem, "Store")) %> <br />
</ItemTemplate> <br />
<EditItemTemplate> <br />
<asp:dropdownList ID="ddlStores" AutoPostBack="True" runat="server" DataTextField="Store" DataValueField="StoreID"></asp:dropdownlist> <br />
</EditItemTemplate> <br />
</asp:TemplateColumn> <br />
<br />
<asp:TemplateColumn HeaderText="AccessLevel"> <br />
<ItemTemplate> <br />
<%# Convert.ToString(DataBinder.Eval(Container.DataItem, "AccessLevel")) %> <br />
</ItemTemplate> <br />
<EditItemTemplate> <br />
<aspropdownList id="ddlAccessLevels" runat="server" DataSource='<%# GetAccessLevels() %>' DataValueField="AccessLevelID" DataTextField="AccessLevel"> <br />
</aspropdownList> <br />
</EditItemTemplate> <br />
</asp:TemplateColumn> <br />
<br />
<asp:TemplateColumn HeaderText="User Name"> <br />
<ItemTemplate> <br />
<asp:Label Text='<%# Convert.ToString(DataBinder.Eval(Container.DataItem,"UserName")) %>' Runat="server" ID="lblUserName"> <br />
</asp:Label> <br />
</ItemTemplate> <br />
<EditItemTemplate> <br />
<asp:TextBox Runat="server" ID="editUserName" Text = '<%# Convert.ToString(DataBinder.Eval(Container.DataItem,"UserName")) %>' Width="150"> <br />
</asp:TextBox> <br />
</EditItemTemplate> <br />
</asp:TemplateColumn> <br />
<br />
<asp:TemplateColumn HeaderText="Full Name"> <br />
<ItemTemplate> <br />
<asp:Label Text='<%# Convert.ToString(DataBinder.Eval(Container.DataItem,"FullName")) %>' Runat="server" ID="Label2"> <br />
</asp:Label> <br />
</ItemTemplate> <br />
<EditItemTemplate> <br />
<asp:TextBox Runat="server" ID="editFullName" Text = '<%# Convert.ToString(DataBinder.Eval(Container.DataItem,"FullName")) %>' Width="150"> <br />
</asp:TextBox> <br />
</EditItemTemplate> <br />
</asp:TemplateColumn> <br />
<asp:TemplateColumn HeaderText="Reports To"> <br />
<ItemTemplate> <br />
<%# Convert.ToString(DataBinder.Eval(Container.DataItem, "UserName")) %> <br />
</ItemTemplate> <br />
<EditItemTemplate> <br />
<aspropdownList runat="server" id="ddlReportTos" DataTextField="UserName" DataValueField="ReportToID" DataSource='<%# GetValues("tbl_Users") %>'> <br />
</aspropdownList> <br />
</EditItemTemplate> <br />
</asp:TemplateColumn> <br />
</Columns> <br />
</asp:datagrid> <br />
</TD> <br />
</TR> <br />
</TABLE> <br />
</form> <br />
</body> <br />
<br />
<br />
<br />
Please help me if you can and send the solution to mcupryk@sun.net.bb Thank you Sincerely.
Please help me if you can and send the solution to mcupryk@sun.net.bb Thank you Sincerely.
|
|
|
|
|
Hi,
How to change the color of status bar?
kalpu
|
|
|
|
|
My application is using a treeview to interact with the user. Opposite to the treeview i'm using a panel which contains content in the form of UserControls(Which often contain several UserControls). Each time the user chooses something in the treeview the content on the panel is changed. This is done by clearing the contents of the panel and disposing the controls which resides on it.
The panel is cleared using, where MainPanelCRF is the Panel:
private void clearPanel()
{
if(this.MainPanelCRF.Controls.Count > 0)
{
foreach(Control control in this.MainPanelCRF.Controls[0].Controls)
{
if(control != null)
{
control.Dispose();
}
}
this.MainPanelCRF.Controls[0].Dispose();
this.MainPanelCRF.Controls.Clear();
}
}
Even though I dispose the UserControls i'm seeing an increase in memory usage each time I change the UserControl on the panel. The memory increase does not seem to stop either. It easily succeeds 100 000K. Shouldn't the Garbage Collector collect the UserConrols that has been disposed? Is it possible that the UserControls is not disposed properly?
This has been giving me a headache for a couple of days now , has anyone got a suggestion as to how I can reduce the memory usage of my application?
Thanks,
Magnus Green
System Developer
Clinsoft AS
Norway
|
|
|
|
|