|
Test270307 wrote: How can i create a object of a class....if the constructor of that class is private??
You can't unless the class gives you a way to create instances other than using the constructors, e.g. static factory methods.
|
|
|
|
|
If it's private, it's for a reason, usually to force you to use a factory method ( as in a static ClassName.Create type method )
In C++, friend classes make this a lot more powerful.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Check out the Factory method and Singleton patterns. You will have a public method, typically called Create() or GetInstance() that calls the private constructor.
Cheers,
Vıkram.
Déjà moo - The feeling that you've seen this bull before.
Join the CP group at NationStates. Password: byalmightybob
|
|
|
|
|
I want to access Local Security Policy (User Rights assignment) using C#. Is it possible?
My requirement is to add/remove users from certain policies programatically.
Thanks,
Pranav
|
|
|
|
|
One Post is Enough.
Regards,
Satips.
|
|
|
|
|
I think you should use IEnumerator iHeirarchy = SecurityManager.PolicyHierarchy(); then you can loop each policy level PolicyLevel polLevel = iHeirarchy.Current as PolicyLevel; and then you can get the codegroup by taking polLevel.RootCodeGroup.Children or get the named permission set polLevel.NamedPermissionSets from here you can manipulate whatever you wan't like removing or adding.
|
|
|
|
|
|
I want to access/modify Local Security Policy (User Rights Assignment) using C#. Is it possible?
My requirement is to add/remove a user from a certain policy.
Thanks in advance,
Pranav
|
|
|
|
|
One Post is Enough.
Regards,
Satips.
|
|
|
|
|
hi,
my problem is how to select data from datagridview1 and transfer the selected data by double clicking the row to datagridview2?
my code:
private void dataGridView3_DoubleClick(object sender, EventArgs e)
{
long itemcode =0;
string description = "";
itemcode = Convert.ToInt64(dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells[0].Value.ToString());
description = dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells[1].Value.ToString();
DataGridViewCell itemCodeCell = new DataGridViewTextBoxCell();
itemCodeCell.Value = itemcode;
DataGridViewCell descriptionCell = new DataGridViewTextBoxCell();
descriptionCell.Value = description;
DataGridViewRow row = new DataGridViewRow();
row.Cells.Add(itemCodeCell);
row.Cells.Add(new DataGridViewTextBoxCell());
row.Cells.Add(new DataGridViewTextBoxCell());
row.Cells.Add(descriptionCell);
string[] rows = new string[]{ itemcode.ToString(), "", "", description };
dataGridView4.Rows.Add(rows);
}
it seems that my program is correct but i receive an exception error on the last part of my code... dataGridView4.Rows.Add(rows);
Exception error message received:
Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.
what will i do??pls. help..
jing
jing
|
|
|
|
|
Hi I am currently making a window application as a project and one of its requirements is to have a report in Excel format. I have search the web about this and have only seen method involving web based applications. Can someone help me? Thankss 
|
|
|
|
|
Try this[^]
Good luck!
Aim small, miss small
|
|
|
|
|
I have a 100MB database of SQLServer. When I made a datagridview using DatagridViewColumnCombox in order that user can choose an item in combobox. When I choose an item, it seems to load data into combobox column. It cause my app running so slowly although this column contains a field about over 1000 records....
Somebody could help me explain why VS.NET uses cache but my app runs slowly
I assume that if I made a combo box and then attached it into datagridview, it ưould seem slower. But, I don't know how to do it....
Sorry about my poor English
Thanks in advance ...
It seem to be a solution or an answer.
|
|
|
|
|
phantanagu wrote: When I choose an item, it seems to load data into combobox column.
It *seems* to ? What code have you written, that you're not sure if it does, or not ?
If you take the SQL that's being run, and run it in SQL Server, how fast is it ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: It *seems* to ? What code have you written, that you're not sure if it does, or not ?
I only assign datasource to combobox column using dataset object,I don't write any code. Because list of items appears slow so I think everytime I select an item in new row, combo box also loads data.
Christian Graus wrote: If you take the SQL that's being run, and run it in SQL Server, how fast is it ?
I am sure that if I run it in SQLServer, it makes me content with speed. If I use a favourite combox, loading of data is OK. But when using DatagridColumnComboBox, I confuse it...
It seem to be a solution or an answer.
|
|
|
|
|
Did you write code to load the data or you've drag/drooped in VS.NET a connection/dataset and so on?
http://stefanprodan.wordpress.com
|
|
|
|
|
I know i can add an IE web browser to a c# app using the Microsoft Web Browser Component, can i do the same to add a Firefox browser?
If not, how would i go about manipulation the Microsoft Web Browser to look like firefox? Ie.. by referencing the Mozilla standards?...
Thanks Heaps
|
|
|
|
|
Search for Mozilla ActiveX. That is an ActiveX component just like Internet Explorer, you can plop it on your form the same way.
|
|
|
|
|
Thanks heaps 
|
|
|
|
|
Hello
How do i modify my C# form in such a way that every time I run it, it will automatically maximize and fit the screen?
thanks in advance 
|
|
|
|
|
In the designer, the form has a WindowState property. Set it to Maximised.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
got it. thanks! 
|
|
|
|
|
good evning every one..i really need ur help guys ..my program like that one in Paint ..finally i can save the file as text in C DRIVE but while opening it can read the data from text but cant display it ( draw the lines..)..note it can save & open the lines only.
---> my question : how can i make the program display the file.
this apart of my code guys :
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Data;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
namespace graphics_practis
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
Point center,radius,v,start,end,a,b;
ArrayList arraypoint=new ArrayList();
ArrayList arraylist_points=new ArrayList();
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button line;
private System.Windows.Forms.Button square;
private System.Windows.Forms.Button circle;
private System.Windows.Forms.Button ellipse;
private System.Windows.Forms.Button polygon;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button ok;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private BinaryFormatter formtter = new BinaryFormatter();
///
/// 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
//
dr = new draw(this.pictureBox1);
}
///
/// 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()
{
this.panel1 = new System.Windows.Forms.Panel();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.line = new System.Windows.Forms.Button();
this.square = new System.Windows.Forms.Button();
this.circle = new System.Windows.Forms.Button();
this.ellipse = new System.Windows.Forms.Button();
this.polygon = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.ok = new System.Windows.Forms.Button();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.MenuText;
this.panel1.Controls.Add(this.pictureBox1);
this.panel1.Location = new System.Drawing.Point(96, 32);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(416, 296);
this.panel1.TabIndex = 0;
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.Window;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(416, 296);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);
this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
//
// line
//
this.line.Location = new System.Drawing.Point(24, 32);
this.line.Name = "line";
this.line.Size = new System.Drawing.Size(40, 23);
this.line.TabIndex = 1;
this.line.Text = "line";
this.line.Click += new System.EventHandler(this.line_Click);
//
// square
//
this.square.Location = new System.Drawing.Point(24, 72);
this.square.Name = "square";
this.square.Size = new System.Drawing.Size(40, 23);
this.square.TabIndex = 2;
this.square.Text = "square";
this.square.Click += new System.EventHandler(this.square_Click);
//
// circle
//
this.circle.Location = new System.Drawing.Point(24, 120);
this.circle.Name = "circle";
this.circle.Size = new System.Drawing.Size(48, 23);
this.circle.TabIndex = 3;
this.circle.Text = "circle";
this.circle.Click += new System.EventHandler(this.circle_Click);
//
// ellipse
//
this.ellipse.Location = new System.Drawing.Point(24, 168);
this.ellipse.Name = "ellipse";
this.ellipse.Size = new System.Drawing.Size(56, 23);
this.ellipse.TabIndex = 4;
this.ellipse.Text = "ellipse";
this.ellipse.Click += new System.EventHandler(this.ellipse_Click);
//
// polygon
//
this.polygon.Location = new System.Drawing.Point(16, 216);
this.polygon.Name = "polygon";
this.polygon.Size = new System.Drawing.Size(56, 23);
this.polygon.TabIndex = 5;
this.polygon.Text = "polygon";
this.polygon.Click += new System.EventHandler(this.polygon_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 264);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(40, 20);
this.textBox1.TabIndex = 6;
this.textBox1.Text = "";
//
// ok
//
this.ok.Location = new System.Drawing.Point(48, 264);
this.ok.Name = "ok";
this.ok.Size = new System.Drawing.Size(32, 23);
this.ok.TabIndex = 7;
this.ok.Text = "ok";
this.ok.Click += new System.EventHandler(this.ok_Click);
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4,
this.menuItem5});
this.menuItem1.Text = "File";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "New";
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "Open";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = "Save";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem5
//
this.menuItem5.Index = 3;
this.menuItem5.Text = "Exit";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 344);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(192, 32);
this.button1.TabIndex = 8;
this.button1.Text = "Change Text Color";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(192, 384);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(192, 32);
this.button2.TabIndex = 9;
this.button2.Text = "Change Background Color";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(528, 445);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.ok);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.polygon);
this.Controls.Add(this.ellipse);
this.Controls.Add(this.circle);
this.Controls.Add(this.square);
this.Controls.Add(this.line);
this.Controls.Add(this.panel1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
#region variables
Graphics g ;
Pen p = new Pen(Color.Black,1);
ArrayList lines = new ArrayList();
ArrayList squeres = new ArrayList();
ArrayList circles = new ArrayList();
ArrayList ellipses = new ArrayList();
ArrayList polygons = new ArrayList();
int drawwhat;
int n ;//for the No. of polygon
draw dr;
#endregion
#region mouse down
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
start.X = e.X;
start.Y = e.Y;
arraylist_points.Add(start);
}
#endregion
#region mouse move
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
g = pictureBox1.CreateGraphics();
if(e.Button == MouseButtons.Left)
{
refresh();
DrawReq(new Point(e.X,e.Y));
}
}
#endregion
#region mouse_up
private void pictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
end.X = e.X;
end.Y = e.Y;
DrawReq();
arraylist_points.Add(end);
}
}
#endregion
#region FormLoad
private void Form1_Load(object sender, System.EventArgs e)
{
Bitmap bmp =
new Bitmap(pictureBox1.Width,
pictureBox1.Height);
pictureBox1.BackgroundImage = bmp;
g = Graphics.FromImage(bmp);
g.Clear(pictureBox1.BackColor);
}
#endregion
private void line_Click(object sender, System.EventArgs e)
{
drawwhat = 1;
}
#region Drawwhat
private void DrawReq()
{
if(drawwhat == 1)
{
dr.line(p,start,end);
Line l = new Line();
l.Pen = p;
l.First = start;
l.Second = end;
lines.Add(l);
l = null;
}
else if(drawwhat == 2)
{
dr.square(new Pen(Color.Black,1),start,end);
Line l = new Line();
l.Pen = p;
l.First = start;
l.Second = end;
squeres.Add(l);
l = null;
}
else if(drawwhat == 3)
{
dr.circle(p,start,end);
Line l = new Line();
l.Pen = p;
l.First = start;
l.Second = end;
circles.Add(l);
l = null;
}
else if(drawwhat == 4)
{
dr.ellipse(p,start,end);
Line l = new Line();
l.Pen = p;
l.First = start;
l.Second = end;
ellipses.Add(l);
l = null;
}
else if (drawwhat == 5 && n!=0)
{
dr.polygon(n,p,start,end);
Polygon np = new Polygon();
np.Pen = p;
np.First = start;
np.Second = end;
np.n = n;
polygons.Add(np);
np = null;
}
}
//______________________________________________________________
private void DrawReq(Point last)// overloading to draw during moving
{
end = last;
if(drawwhat == 1)
{
dr.line(p,start,end);
}
else if(drawwhat == 2)
{
dr.square(p,start,end);
}
else if(drawwhat == 3)
{
dr.circle(p,start,end);
}
else if(drawwhat == 4)
{
dr.ellipse(p,start,end);
}
else if (drawwhat == 5)
{
dr.polygon(n,p,start,end);
}
}
//________________________________________________________________
//________________________________________________________________
#endregion
#region Refresh
private void refresh()
{
pictureBox1.Refresh();
foreach(Line l in lines)
{
dr.line(l.Pen,l.First,l.Second);
}
foreach(Line l in squeres)
{
dr.square(l.Pen,l.First,l.Second);
}
foreach(Line l in circles)
{
dr.circle(l.Pen,l.First,l.Second);
}
foreach(Line l in ellipses)
{
dr.ellipse(l.Pen,l.First,l.Second);
}
foreach(Polygon p in polygons)
{
dr.polygon(p.n,p.Pen,p.First,p.Second);
}
}
#endregion
private void square_Click(object sender, System.EventArgs e)
{
drawwhat = 2;
}
private void circle_Click(object sender, System.EventArgs e)
{
drawwhat = 3;
}
private void pictureBox1_Click(object sender, System.EventArgs e)
{
}
private void ellipse_Click(object sender, System.EventArgs e)
{
drawwhat = 4;
}
private void polygon_Click(object sender, System.EventArgs e)
{
drawwhat = 5;
}
private void ok_Click(object sender, System.EventArgs e)
{
try
{
n = int.Parse(textBox1.Text.ToString());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
// save the file
string str_Line;
System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
StreamWriter streamWriter=new StreamWriter(fs);
if(drawwhat==1)
{
for(int j=0;j
|
|
|
|
|
No-one is going to read all of this.
mr jets wrote: private void menuItem3_Click(object sender, System.EventArgs e)
{
//open the file
string str_reader;
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
StreamReader streamReader=new
StreamReader(openFileDialog1.FileName);
str_reader=streamReader.ReadToEnd();
MessageBox.Show(str_reader);
streamReader.Close();
}
This code assigns your file contents to a string, which you then discard ( it's a local variable, so it disappears after the function ends ). By what process did you expect your program to do anything with this data ?
mr jets wrote: for(int j=0;j {
streamWriter.WriteLine("Line");
start=(Point)arraylist_points[j];
end=(Point)arraylist_points[j+1];
str_Line=start.ToString()+end.ToString();
streamWriter.WriteLine(str_Line);
j++;
}
streamWriter.Flush();
streamWriter.Close();
fs.Close();
You need to reverse this process and fill your array of points with the data you've read in.
Your program is not like Paint. Paint deals in raster info, you're doing a drawing package.
You shouldn't use a picture box, that's a waste of time, write your own handler for the paint message.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
heloo christian ..u are my hero man ..there was awrong with my save code..:
// save the file
string str_Line;
System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
StreamWriter streamWriter=new StreamWriter(fs);
if(drawwhat==1)
{
for(int j=0;j
|
|
|
|
|