|
|
try something like this:
using System.Drawing.Drawing2D;
private bool clearImage = false;
protected override void OnPaint(PaintEventArgs e)
{
if (this.clearImage)
{
using (Pen clearPen = new Pen(this.BackColor))
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawEllipse(clearPen, 100, 100, 2, 2);
this.clearImage = false;
}
}
else
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawEllipse(Pens.Red, 100, 100, 2, 2);
}
}
then your button click event
this.clearImage = true;
this.Refresh();
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
hi
what is the best way for open connection to database ?
1.open in form1 - and close and open again in form2 ?
2.open in form1 as static - and use it for all form's (stay open all the time) ?
3.after I clossing the connection is it good to do - Connection.dispose() ?
I work on C#, and connect to sqlCE, Windows mobile 2005
thank's in addvance
|
|
|
|
|
I prefer method one. SQL server has connection pooling anyway, so it's likely to get re-used behind the scenes. And it clearly separates the functionality of the two forms, so one doesn't rely on another
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Unless totally unavoidable, don't use option 2) (open all the time), considered very naughty.
Go for option 1) when you can.
As far as 3) is concerned try to do it like this:
using (SqlConnection myConnection = new SqlConnection(.....))
{
myConnection.Open();
}
by doing so you avoid having to worry about Dispose() and Close().
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I use a static class for the DAL and close the connection after each operation.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
But when do you connect?
Generally I instantiate my DAL in Main, the DAL instantiates the connection and connects.
Then I can pass a reference to the DAL to the constructor of any Form that needs it.
Each method in the DAL opens and closes the connection as necessary.
using ( MyDAL dal = new MyDal ( ... ) )
{
S.W.F.A.Run ( new Form1 ( dal ) ) ;
S.W.F.A.Run ( new Form2 ( dal ) ) ;
...
}
A form (or other application) shouldn't know about the database at all.
|
|
|
|
|
Good afternoon.
I have the following code:
foreach (DataGridViewRow row in this.dgv.Rows)
{
int intID = (int)dgv.Rows[row.Index].Cells[0].Value;
string strType = dgv.Rows[row.Index].Cells[1].Value.ToString();
string strValue = dgv.Rows[row.Index].Cells[2].Value.ToString();
string strVoidDate = dgv.Rows[row.Index].Cells[3].Value.ToString();
d.UpdateAllowedTypes(intID, strType, strValue, strVoidDate);
}
The problem is when the last row is read, it throws the unhandled error. If I put a try catch in I'll have to do something with error. What I am attempting to do is to test for a blank ID # or make sure it doesn't read the next blank reocrd.
Any suggestion? WHEELS
|
|
|
|
|
Which line does the error occur on? If it happens on the very first line of your code snippet, then just continue; if row == null. I'm not certain why this hapens though - maybe it's the 'add new record' line?
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Thank you Computafreak. I finally figured it out:
foreach (DataGridViewRow row in this.dgv.Rows)
{
int intRowCount = dgv.Rows.Count;
if (dgv.Rows[row.Index].Cells[0].Value != null)
{
int intID = (int)dgv.Rows[row.Index].Cells[0].Value;
string strType = dgv.Rows[row.Index].Cells[1].Value.ToString();
string strValue = dgv.Rows[row.Index].Cells[2].Value.ToString();
string strVoidDate = dgv.Rows[row.Index].Cells[3].Value.ToString();
d.UpdateAllowedTypes(intID, strType, strValue, strVoidDate);
}
intctr++;
}
MessageBox.Show("Completed update.");
WHEELS
|
|
|
|
|
Hello,
Im new in programing and this is the reason why i ask you for help.
I had a program and after i click on a button i would like to show up a new form where is a ZedGraph sample.
I did everything like in Quick Start Tutorial
( http://zedgraph.org/wiki/index.php?title=CSharp_Reference_Code_for_Sample_Charts ).
Than i run the Build Solution and got no error message. But when i run the application and click on the button i got an unhandled exception message:
"Could not load file or assembly 'ZedGraph, version=5.1.5.28844, Culture=neutral, PublicKeyToken=02a83cbd123fcd60' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'ZedGraph, Version=5.1.5.28844, Culture=neutral, PublicKeyToken=02a83cbd123fcd60' or one of its dependencies. The system cannot find the file specified.
File name: 'ZedGraph, Version=5.1.5.28844, Culture=neutral, PublicKeyToken=02a83cbd123fcd60'
at Proba_5___XML.graf.InitializeComponent()
at Proba_5___XML.graf..ctor() in D:\-= FEI =-\-= Diplomovka =-\Programozas\Program - Utlmovy Plan\Proba 21\Proba 5 - XML\graf.cs:line 17
at Proba_5___XML.Form1.button7_Click(Object sender, EventArgs e) in D:\-= FEI =-\-= Diplomovka =-\Programozas\Program - Utlmovy Plan\Proba 21\Proba 5 - XML\Form1.cs:line 641
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)"
I dont know what i did wrong. Ill be happy for any help.
Regards
Tom
|
|
|
|
|
this happens when you have the wrong version DLL of zedgraph in the directory (or didnt copy it to the debug or release directory (did you look there??))
also if you didnt include the reference,
goto add reference.
easy fix.
|
|
|
|
|
Hi, everyone, I'm building an application in VC# 2008 that displays a bitmap into a pictureBox but my bitmap it's always displayed at my top-left corner, I know that I can center it, but I want to position the bitmap at the bottom-left corner. Does anyone know how can I do that? Thanks for your time.
|
|
|
|
|
There are two methods that spring to mind.
1) subclass the PictureBox and do the paint handling yoursef. Very complicated! Not my first choice.
2) create an in-memory bitnap the same size as your PictureBox's ClientRectangle with a transparent background, draw the required image in the required location and then add this new bitmap as the Image for the PictureBox. Sounds more complicated, but is much easier to do. My recommendation.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
That really sounds complicated but I understand you perfectly. Actually I made a proof project and this is the code:
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Bitmap OrigImage = new Bitmap(pictureBox2.Image);
int targetTop = pictureBox1.Height - OrigImage.Height;
int targetLeft = 0;
int targetWidth = pictureBox1.Width;
int targetHeight = pictureBox1.Height;
int sourceWidth = pictureBox1.Width;
int sourceHeight = pictureBox1.Height;
Graphics g = Graphics.FromImage(pictureBox1.Image);
g.DrawImage(OrigImage,new Rectangle(targetLeft, targetTop, targetWidth, targetHeight),new Rectangle(0,0, sourceWidth, sourceHeight),GraphicsUnit.Pixel);
It worked prefectly. That's exactly what I wanted.
Thanks a lot
|
|
|
|
|
Pleased to help.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I would not create a new image, instead resize the control to match the image size, and locate it appropriately.
And of course, if I were to paint the image myself, there would be no PictureBox at all.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi all,
I have an issue with the report viewer. I created my reports with reportviewer tool and everything
works ok.
My problem is, once I created a report and close the report form and then I tried to update
something on my database I always received and error message that the database cannot been opened.
So my question here is ... How can I force reportviewer to close any database opened after I close
my report form?
Here is the complete code of my report form:
<pre>
using System;
using System.Windows.Forms;
namespace SACK
{
public partial class frmReportes : Form
{
public frmReportes()
{
InitializeComponent();
}
private void frmReportes_Load(object sender, EventArgs e)
{
this.repViewer.RefreshReport();
}
private void btnSalir_Click(object sender, EventArgs e)
{
this.Close();
}
private void btbGenerarReporte_Click(object sender, EventArgs e)
{
DateTime fechaIni = Convert.ToDateTime(dtpFechaIni.Text);
DateTime fechaFin = Convert.ToDateTime(dtpFechaFinal.Text);
// Reporte de Entradas
if (rbuEntradas.Checked)
{
try
{
this.tPrinterTableAdapter.FillByEntradas(this.KardexPrinterDBDataSet.tProductos, fechaIni, fechaFin);
this.repViewer.LocalReport.ReportEmbeddedResource = "SACK.ReportByEntradas.rdlc";
this.repViewer.RefreshReport();
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
// Reporte de Salidas
if (rbuSalidas.Checked)
{
try
{
this.tPrinterTableAdapter.FillBySalidas(this.KardexPrinterDBDataSet.tProductos, fechaIni, fechaFin);
this.repViewer.RefreshReport();
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
// Reporte de Entradas / Salidas
if (rbuSalidas.Checked)
{
try
{
this.tPrinterTableAdapter.FillByEntradasSalidas(this.KardexPrinterDBDataSet.tProductos, fechaIni, fechaFin);
this.repViewer.RefreshReport();
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
// Reporte de Existencias
if (rbuSalidas.Checked)
{
try
{
this.tPrinterTableAdapter.FillByExistencias(this.KardexPrinterDBDataSet.tProductos, fechaIni, fechaFin);
this.repViewer.RefreshReport();
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
}
}
</pre>
Hope someone can help me on this... thank you!:cool
modified on Tuesday, August 11, 2009 2:56 PM
|
|
|
|
|
Hey,
This is a question I've had for a while and we just worked around it, but our libraries have grown substantially and it is becoming a bit of a pain to deal with. Perhaps one of you can enlighten me.
Say I create a class library called LibraryA. LibraryA has a dependency on another project called LibraryB (it has a reference to this other project).
When LibraryA is built, it properly adds LibraryB to its output folder. However, if I now actually use LibraryA in an application (by adding a reference to it), LibraryB doesn't get included and everything goes up in flames, nobody spared. I am forced to add a reference to LibraryA and LibraryB for it to work properly.
If you add a reference to one of the standard .NET libraries, it automatically adds a reference to all its dependencies. Is there a way to reproduce this behaviour with our own libraries?
|
|
|
|
|
Mike Marynowski wrote: If you add a reference to one of the standard .NET libraries, it automatically adds a reference to all its dependencies. Is there a way to reproduce this behaviour with our own libraries?
It's not quite the same effect, but marking your assemblies as CLS-compliant will require you to include all of the necessary references in each project. It may introduce other issues that need to be resolved in your code, but in general CLS-compliance is a good thing, especially for libraries that will be consumed by multiple projects.
Short of that, there is no way to automatically inlcude the references of referenced projects. The best option would be to introduce a post-build event that copies the necessary files or simply include the correct projects as references (even if they aren't used), which can be done whether the assemblies are CLS-compliant or not.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Scott Dorman wrote: Short of that, there is no way to automatically inlcude the references of referenced projects
Are you saying that you know for a fact that there is no way, or just that there is no way that you are aware of?
I would be very surprised if there actually was NO WAY of doing it. I doubt the behaviour of the standard .NET libraries is somehow hard-coded into Visual Studio - there has to be a metadata file or something else that causes dependency libraries to be added when the dependent library is referenced.
Is this perhaps standard behaviour for libraries registered in the GAC? I haven't tried adding my libraries to the GAC and then referncing it.
|
|
|
|
|
Correct, there is no way to do this. What behavior are you referring to in Visual Studio? If I add a reference to System.Data without already having a reference to System, it doesn't add both references, only the one I specifically told it to add.
Registering the library in the GAC would have no affect on this behavior whatsoever.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Madness I say!
I could swear I've added a reference to a system assembly before and it added more than one reference...but perhaps I'm just delusional.
If I don't reply again, it means I couldn't figure out where I saw that happen...if I figure it out, I'll reply again, lol.
|
|
|
|
|
foreach (DataGridViewRow dr in dgproducts.Rows)
{
if (Convert.ToInt32(dr.Cells[9].Value) < Convert.ToInt32(dr.Cells[6].Value))
{
## //i need to color this row here
}
}
## i need to colour the particular row at that point of the loop
i cant find anything like in that intellisense and sub-intellisense
maybe am not checking well.
any help plz
|
|
|
|
|