|
Is this for an embedded system? Otherwise quibbling about the overhead for a few hundred objects seems pretty silly.
Anyway, since you didn't say how long the "short string" is, there's no way to guess.
As far as the value type stuff goes, there can be many references to one string. In fact, many identical string literals in your code will all result in the same string in a "constant pool" that is shared (that is, all the places where it is used in your code will instead have a reference to that one constant string instance).
> Now, if 100 objects have this string key, it will be 100x the string value.
No, that's not correct. Of course, there is an exception and it depends on how the references are created. If you create a hundred of these:
class MemHawg
{
string name;
public MemHawg( string name )
{
this.name = new string( name );
}
}
Then it will take more memory than this would:
class MemMiser
{
string name;
public MemMiser( string name )
{
this.name = name;
}
}
The first one makes a (somewhat useless) copy of the the string passed in, while the second one just has a reference to the one string. So in the second case, you'll have 100 objects that all refer to the same one string.
Of course, the latter implementation makes more sense, since there isn't much sense in duplicating immutable objects.
Matt Gerrans
|
|
|
|
|
Hellos friends ,I need that my printer print my document in mirror,I want manipulate this from c#,anyone help me.
Regards bigmega
|
|
|
|
|
In your even thandler for the PrintDocument.PrintPage event (or override of OnPrintPage if extending PrintDocument , which is usually a good idea for encapsulation) you need to apply a transformation matrix to the Graphics object by assigning the identity matrix to the Graphics.Transform property (the world transform) with either M11 or M22 negated to flip on the y-axis or x-axis, respectively.
For example:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class FlipExample : Form
{
static void Main()
{
Application.Run(new FlipExample());
}
RectangleF left;
RectangleF right;
PointF[] triangle;
StringFormat format;
Matrix flipTransform;
FlipExample()
{
Text = "Flip Example";
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw |
ControlStyles.UserPaint, true);
format = StringFormat.GenericDefault;
format.Alignment = StringAlignment.Center;
OnResize(EventArgs.Empty);
}
void DrawCaption(Graphics g, RectangleF r, string caption)
{
g.DrawString(caption, Font, SystemBrushes.ControlText,
r, format);
}
void DrawTriangle(Graphics g, RectangleF r, bool flip)
{
if (flip)
{
g.Transform = flipTransform;
g.TranslateTransform(r.X, 0f, MatrixOrder.Append);
}
else
{
g.ResetTransform();
}
g.FillPolygon(SystemBrushes.ControlText, triangle);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
DrawCaption(g, left, "Normal");
DrawCaption(g, right, "Flipped and Translated");
DrawTriangle(g, left, false);
DrawTriangle(g, right, true);
}
protected override void OnResize(EventArgs e)
{
float halfWidth = Width / 2f;
float halfFont = Font.Height / 2f;
left = new RectangleF(0f, 0f, halfWidth, (float)Height);
right = new RectangleF(halfWidth, 0f, halfWidth, (float)Height);
flipTransform = new Matrix(-1,0,0,1,halfWidth,0);
triangle = new PointF[] {
new PointF(halfWidth, halfFont),
new PointF(halfWidth, (float)Height
- SystemInformation.CaptionHeight - halfFont * 2f),
new PointF(0f, Height / 2f)};
base.OnResize(e);
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am trying to make windows installer uninstall the old version and install a new version upon a new release. I found a property RemovePreviousVersions and set it to true.
Accorting to documentation UpgradeCode must not change and ProductCode must be difference. After the install, I go to the Add/Remove programs and see both versions on the list. Is there something that I'm missing?
|
|
|
|
|
Asad Hussain wrote:
Accorting to documentation UpgradeCode must not change and ProductCode must be difference.
That is correct. So is it? To easily find out, download the MSI SDK from http://msdn.microsoft.com/platformsdk[^] which installs Orca.msi into the Platform SDK's Bin directory. Then install that. You can open the MSI packages in Orca. Find the Property table and make sure that for both packages the UpgradeCode property value is the same.
For major installs, you must also change the major version number. Minor installs only change the minor version number. For changes to the build(third) number, the ProductCode should not change. Read Patching and Upgrades[^] in the MSI SDK documentation for more information about package versioning rules.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have a similar problem, on looking at the MSI tables it appears there is some default 1.0.0 version, and from what I can see your version needs to supersede that.
From the Upgrade table:
{742006A9-F10B-4A30-AD73-B05C1875B9AE} 0.0.2 258 NEWERPRODUCTFOUND <br />
<br />
{742006A9-F10B-4A30-AD73-B05C1875B9AE} 1.0.0.0 0.0.2 256 PREVIOUSVERSIONSINSTALLED
Any thoughts?
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
If you take a look at the documentation for the Upgrade table in the MSI SDK (online at http://msdn.microsoft.com/library[^], of course) you'll see that the bits Attribute column are flags and you can see their values.
What's happening above is that the first record is only for detection of newer products, but does not remove them. The second record will remove any products between 1.0.0.0 (inclusive) to 0.0.2 (exlusive).
With that in mind, you should've started your version at 1.0.0 and must have set RemovePreviousVersions to true originally. If you modify your table manually you can fix these problems and in future updates not have to worry about it.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I am having an error for which I have no clue whether the problem is with my machine / IDE or something other. I checked out the code from CVS (C# ) and when I try compiling the code, I get the following error:
fatal error CS0013: Unexpected error writing metadata to file 'filepath\filename.dll' -- 'Unspecified error '
The project that I am building is in C# and its a class library type. I have Visual Sudio .NET 2003 installed on my machine running windows XP. I tried looking up MSDN and what I could see there was just these 3 possible options and none of them work.
>>Compiler Error CS0013
>>Unexpected error writing metadata to file 'file' — 'description'
>>The .NET Framework common language runtime failed to emit metadata. This could be a number of problems:
>>1. Disk full.
>>2. Corrupt Visual Studio installation; reinstall Visual Studio.
>>3. Corrupt common language runtime; reinstall the common language runtime.
I have no clue what is wrong. I have tried google / MSDN but of no avail. Please help me.
Thanks in Advance,
Divick
|
|
|
|
|
Most likely this is problem #3. Visual Studio .NET is just a client that uses the CLR and the designer classes defined mostly by the BCL (base class library), implementing a few interfaces internally to facilitate design-time features.
Go to Add/Remove Programs and find the entry for the Microsoft .NET Framework and uninstall it. Either download it (whichever version you need: VS.NET 2002 requires .NET 1.0 and VS.NET 2003 requires .NET 1.1) from http://msdn.microsoft.com/netframework[^] or install it from the CD that contains VS.NET. Make sure you have all necessary updates from Windows Update (or you can download them separately from the URL above as well).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have already tried this option but it doesn't work. I don't have the update CD instead I tried connecting directly but the setup says that "No service releases are available at this time."
Divick
|
|
|
|
|
That's for Visual Studio .NET. VS.NET != .NET. VS.NET is only an Integrated Development Environment (IDE). The .NET Framework is a separate component. You must download the .NET Framework 1.0 SP3 or .NET Framework 1.1 SP1 from either Windows Update or the download center, which is linked from http://msdn.microsoft.com/netframework[^].
VS.NET is what you use to write programs for the .NET Framework, while the .NET Framework is a runtime and base class library.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have tried that as well. I downloaded .NET Framework 1.1 SP1 from the link above and then tried to recompile, but again the same error.
Divick
|
|
|
|
|
You may have to uninstall both the .NET Framework and Visual Studio .NET, then. Make sure you uninstall them both and clean-up the directories by deleting %WINDIR%\Microsoft.NET\Framework\v1.1.4322 and %ProgramFiles%\Microsoft Visual Studio .NET 2003 (assuming that's where you install VS.NET). Then re-install.
Something has been corrupted and I don't know what. Be sure to search for that error in the Microsoft Knowledge Base at http://support.microsoft.com/search[^] and see if you find anything.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Good day. I have this scenario wherein I have a number of 'user controls' to be placed on C# forms. These controls are reused which means that they are placed on the forms of our application, depending on the user. I want to keep all of the forms' events in a single separate class called "Events.cs".
In summary, these is how it goes:
1. The user chooses which controls to be included in the form.
2. Upon raising an event for a user control (clicking a button), the control will raise an event listed on the separate class (Events.cs).
3. The events class will be the one to access the main form (where the user controls are placed); and do the necessary changes to the form and perform commands like database access.
Is this possible? What is the best approach in doing this?
|
|
|
|
|
The container that accepts these controls must add an event handler for whatever events you want to handle. That event handle is defined by the class contained in Events.cs (that's just a filename, BTW, not a class).
So that the container control can add handlers the event handlers - either instance methods or static methods - must be either public or internal .
An example of adding an event handlers follows:
control1.Click += new EventHandler(someClass.control1_Click); Please note that what you actually call the event handler method doesn't matter (so long as it doesn't conflict with another method or property name) and that different events have different delegates (event handlers), so be sure to read the documentation for the event before wiring it up to an event handler (because that event handler must have the same method signature as the delegate that defines the event).
For more information about handling and raising events, read Handling and Raising Events[^] 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] [My Blog]
|
|
|
|
|
Thanks very much Heath. I tried what you said, but the problem is, I can't find a way for the events class (on the events.cs filename) to communicate or talk back to the form where the control is located.
Like for example this very simple scenario.
- the user control is simply a button named 'btnControl'
- i then drag the 'btnControl' to a form named
'contrainer', which also has a textbox in it called 'txtTest', to verify if the user control can talk to the form via a separate events class.
- remember the events of all the controls, which includes 'btnControl' are raised on a separate class called 'events'. Meaning the user controls have does not communicate directly to the form it has been placed.
- so upon click the 'btnControl', i raise an event on the 'events' class, which will change the text of 'txtTest' to "Add button clicked". But i can't seem to communicate back to the opened form, without opening a new form.
Thanks.
|
|
|
|
|
The first parameter of an event handler - typically called sender (it really doesn't matter what the parameter name is, though) - is the control that raised the event. Cast it to the Type like Control to call methods on it, which must be public or internal .
To handle events of a member of another control (your UserControl you dropped on a Form ) you either need to reflect those events in the container control (like define an event called TextBox1Click ) or make the entire field public or internal (this is not a good idea, though, since you expose the entire control to calling code - extremely bad for library developers).
How you handle the event and how you hook up the event all depends on member access and having an instance of a class (or define the event handlers as static methods), so pass an instance of whatever forms and controls necessary in order to hook-up events and handle them.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
i am trying to use managed ASa client to interact with Sybase database.
I am passing a select command and a connection to my data adapter. The second line of my example will create an instance of command bulider. Upto this much working fine. I am getting "invalid Cast exception " when my control flow come to the third line of example.
Any idea
Eg:
this.PlannedClient=new AsaDataAdapter(SqlCommand,Conn);<br />
AsaCommandBuilder Bld=new AsaCommandBuilder(this.PlannedClient);<br />
this.PlannedClient.InsertCommand = Bld.GetInsertCommand();<br />
this.PlannedClient.UpdateCommand = Bld.GetUpdateCommand();<br />
this.PlannedClient.DeleteCommand = Bld.GetDeleteCommand();<br />
this.Planned=new DataSet("Planned");<br />
this.PlannedClient.Fill(Planned,"Trnload");
Sreejith Nair
[ My Articles ]
|
|
|
|
|
sreejith ss nair wrote:
this.PlannedClient.InsertCommand = Bld.GetInsertCommand();<br />
this.PlannedClient.UpdateCommand = Bld.GetUpdateCommand();<br />
this.PlannedClient.DeleteCommand = Bld.GetDeleteCommand();
Those lines are unnecessary. The AsaCommandBuilder constructor is suppose to assign those. The problem is that you need to cast them to AsaCommand (I'm assuming, if they followed the naming guidelines correctly), but you shoudln't execute those three lines. You're just duplicating code.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have picturboxes added to a panel at run time. I need to draw a line between two picture boxes and also need to get the respective picturebox tags. The line has to be drawn on the panel by clicking on the one picturebox and dragging the mouse and leaving on the other picturebox. Is it possible ??
Thanks
ninja
|
|
|
|
|
ninja2605 wrote:
picturebox tags
What do you mean by "tags"?
This is possible, but you'll need to extend a container control - like UserControl - and override OnPaint (always override when possible instead of handling events from within derivative classes). Use the Graphics object passed to you in the PaintEventArgs.Graphics property to draw a line. You could also just handle the Paint event from outside the current container control (ex: the Form on which you placed the two PictureBox controls), but I (and pretty much any other developer) find that encapsulating functionality makes it esier to reuse.
Let me suggestion, however, that for complete control you should consider not using two PictureBox controls and instead drawing the pictures yourself. Now wait, don't get scared.
It's actually quite easy using the Graphics object in the OnPaint override that I mentioned before. It has a DrawImage method (overloaded methods, actually). All you need to take care of is where to draw the top-left corner.
Why do I suggest this? Because then you could have a single control (in this case, just extend Control to avoid unnecessary overhead) with a couple of Image type properties defined. Override a few of the mouse event handlers (like OnMouseDown , OnMouseMove , and OnMouseUp ) to track the mouse and draw a line between the pictures. Without using complicated layered windows (which is only supported in Windows 2000 and newer anyway) this is the only way to have the line you draw overlap the images if that's what you want.
When overriding event handlers, be sure to call base.OnEventName otherwise the default implementation (when applicable, which is in most cases) is not executed and the actual event is not fired). Only in a few rare cases (like when handling windows messages in WndProc that you want ignored) should you not call the base class's implementation. In what order you do it greatly depends on what you're doing. For painting, for example, you'll want to call base.OnPaint first so that any owner-drawn decorations are drawn first, then draw your decorations on top of them.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for the reply Heath. By Tag i mean PicturBox.Tag property. Here is my code, difficult to understand though as there r few commments. Now you might get the clear picture as to what i am trying to achieve. There is drag drop functionality, where i am trying to link images and get their names in a string which i am going to use later. So when i do drag drop i should be able to draw line between images and on the panel.
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
namespace medappzDMS.folderList
{
///
/// Summary description for fmlinks.
///
public class fmlinks : System.Windows.Forms.Form
{
private CustomAutoScrollPanel.ScrollablePanel panel1;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage thumbnails;
private System.Windows.Forms.TabPage actualsize;
private System.Windows.Forms.PictureBox[] pb;
private System.Windows.Forms.Label[] lbl;
//private System.ComponentModel.IContainer components;
//private System.Drawing.Image _image = null;
private int _margin = 50;
private bool m_MouseIsDown=false;
private bool m_IsDragDrop=true;
//private bool panelmousedown=false;
//private string[] arrfilename;
private string[] arrfileindex1;
private string[] arrfileindex2;
// private char[] charfileindex1;
private string[] filename;
private string[] filename1;
private string locallink=null;
private string linkfrom=null;
private int j=0;
private bool hascolor=false;
private System.Drawing.Image _image = null;
private string pbcolor;
private int x1=0,y1=0,x2=0,y2=0;
Rectangle SelectRect = new Rectangle();
Point ps=new Point();
private System.Windows.Forms.Label lblviewcurlinks;
private System.Windows.Forms.Label lblcurlinks;
Point pe=new Point();
private System.Windows.Forms.ToolTip toolTip1;
private System.ComponentModel.IContainer components;
private string startcoordinates=null;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.NumericUpDown numericUpDown5;
private System.Windows.Forms.NumericUpDown numericUpDown6;
private string endcoordinates=null;
private System.Drawing.Image Image
{
get { return _image; }
}
public fmlinks()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
string [] fileEntries = Directory.GetFiles(utils.imgfolderpath);
j=fileEntries.Length;
//arrfilename=new string[j];
arrfileindex1=new string[j];
arrfileindex2=new string[j];
//charfileindex1=new char[]{'#'};
filename=new string[j];
filename1=new string[j*3];
//
// 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()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(fmlinks));
this.tabControl1 = new System.Windows.Forms.TabControl();
this.thumbnails = new System.Windows.Forms.TabPage();
this.numericUpDown6 = new System.Windows.Forms.NumericUpDown();
this.numericUpDown5 = new System.Windows.Forms.NumericUpDown();
this.lblviewcurlinks = new System.Windows.Forms.Label();
this.lblcurlinks = new System.Windows.Forms.Label();
this.panel1 = new CustomAutoScrollPanel.ScrollablePanel();
this.panel2 = new System.Windows.Forms.Panel();
this.actualsize = new System.Windows.Forms.TabPage();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.tabControl1.SuspendLayout();
this.thumbnails.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown6)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown5)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.thumbnails);
this.tabControl1.Controls.Add(this.actualsize);
this.tabControl1.Location = new System.Drawing.Point(8, 8);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(580, 520);
this.tabControl1.TabIndex = 0;
this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged);
//
// thumbnails
//
this.thumbnails.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("thumbnails.BackgroundImage")));
this.thumbnails.Controls.Add(this.numericUpDown6);
this.thumbnails.Controls.Add(this.numericUpDown5);
this.thumbnails.Controls.Add(this.lblviewcurlinks);
this.thumbnails.Controls.Add(this.lblcurlinks);
this.thumbnails.Controls.Add(this.panel1);
this.thumbnails.Location = new System.Drawing.Point(4, 22);
this.thumbnails.Name = "thumbnails";
this.thumbnails.Size = new System.Drawing.Size(572, 494);
this.thumbnails.TabIndex = 0;
this.thumbnails.Text = "Thumbnails";
//
// numericUpDown6
//
this.numericUpDown6.Location = new System.Drawing.Point(352, 8);
this.numericUpDown6.Maximum = new System.Decimal(new int[] {
100000,
0,
0,
0});
this.numericUpDown6.Name = "numericUpDown6";
this.numericUpDown6.TabIndex = 4;
this.numericUpDown6.Visible = false;
this.numericUpDown6.ValueChanged += new System.EventHandler(this.numericUpDown6_ValueChanged);
//
// numericUpDown5
//
this.numericUpDown5.Location = new System.Drawing.Point(488, 8);
this.numericUpDown5.Maximum = new System.Decimal(new int[] {
100000,
0,
0,
0});
this.numericUpDown5.Name = "numericUpDown5";
this.numericUpDown5.TabIndex = 3;
this.numericUpDown5.Visible = false;
this.numericUpDown5.ValueChanged += new System.EventHandler(this.numericUpDown5_ValueChanged);
//
// lblviewcurlinks
//
this.lblviewcurlinks.AutoSize = true;
this.lblviewcurlinks.Location = new System.Drawing.Point(192, 16);
this.lblviewcurlinks.Name = "lblviewcurlinks";
this.lblviewcurlinks.Size = new System.Drawing.Size(0, 16);
this.lblviewcurlinks.TabIndex = 2;
//
// lblcurlinks
//
this.lblcurlinks.Location = new System.Drawing.Point(48, 16);
this.lblcurlinks.Name = "lblcurlinks";
this.lblcurlinks.Size = new System.Drawing.Size(72, 23);
this.lblcurlinks.TabIndex = 1;
this.lblcurlinks.Text = "Current Link";
//
// panel1
//
this.panel1.AutoScroll = true;
this.panel1.AutoScrollHorizontalMaximum = 100;
this.panel1.AutoScrollHorizontalMinimum = 0;
this.panel1.AutoScrollHPos = 0;
this.panel1.AutoScrollVerticalMaximum = 100;
this.panel1.AutoScrollVerticalMinimum = 0;
this.panel1.AutoScrollVPos = 0;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.Add(this.panel2);
this.panel1.EnableAutoScrollHorizontal = true;
this.panel1.EnableAutoScrollVertical = true;
this.panel1.Location = new System.Drawing.Point(8, 48);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(568, 440);
this.panel1.TabIndex = 0;
this.panel1.VisibleAutoScrollHorizontal = true;
this.panel1.VisibleAutoScrollVertical = true;
this.panel1.ScrollVertical += new System.Windows.Forms.ScrollEventHandler(this.panel1_ScrollVertical);
this.panel1.ScrollHorizontal += new System.Windows.Forms.ScrollEventHandler(this.panel1_ScrollHorizontal);
this.panel1.ScrollMouseWheel += new System.Windows.Forms.MouseEventHandler(this.panel1_ScrollMouseWheel);
//
// panel2
//
this.panel2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel2.BackgroundImage")));
this.panel2.Location = new System.Drawing.Point(24, 16);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(700, 750);
this.panel2.TabIndex = 0;
this.panel2.Click += new System.EventHandler(this.panel2_Click);
this.panel2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp);
this.panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
this.panel2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
this.panel2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
//
// actualsize
//
this.actualsize.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("actualsize.BackgroundImage")));
this.actualsize.Location = new System.Drawing.Point(4, 22);
this.actualsize.Name = "actualsize";
this.actualsize.Size = new System.Drawing.Size(648, 438);
this.actualsize.TabIndex = 1;
this.actualsize.Text = "Actual Size";
//
// fmlinks
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(592, 542);
this.Controls.Add(this.tabControl1);
this.Name = "fmlinks";
this.Load += new System.EventHandler(this.fmlinks_Load);
this.tabControl1.ResumeLayout(false);
this.thumbnails.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown6)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown5)).EndInit();
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void DisplayThumbnails()
{
//string sourceDir="g:\\images";
string [] fileEntries = Directory.GetFiles(utils.imgfolderpath);
int j=fileEntries.Length;
//get the first and second filename numbers in an array for example for file 1_2_medhistory.png
//getting 1 and 2
for(int i=0; i<j; i++)
="" {
="" char[]="" charfileindex;
="" charfileindex="new" char[]{'_'};
="" int="" index="fileEntries[i].ToString().LastIndexOf(@"\");
" string="" s="fileEntries[i].ToString().Substring(index+1);
" filename[i]="s;
"
="" filename1="filename[i].Split(charfileindex);
" arrfileindex1[i]="filename1[0];
" arrfileindex2[i]="filename1[1];
" }
="" try
="" pb="new" system.windows.forms.picturebox[j];
="" lbl="new" system.windows.forms.label[j];
="" messagebox.show(fileindex2max.tostring());
="" for(int="" i="0" ;="" <="" j="" i++="" )
="" folderpath="g:\\images" ;
="" image="" img="Image.FromFile(folderpath" +="" @"\"="" (i+1)="" "_"+k+"_medicalhistorypage_done.png");
="" if(file.exists(utils.imgfolderpath="" (arrfileindex1[i])="" "_"="" (arrfileindex2[i])="" "_medicalhistorypage_done.png"))
="" pb[i]="new" picturebox();
="" lbl[i]="new" label();
="" pb[i].image="Image.FromFile(folderpath" "_medicalhistorypage_done.png");
="" _image="Image.FromFile(utils.imgfolderpath" pb[i].backcolor="Color.Black;
" pb[i].width="150;
" pb[i].name="arrfileindex1[i].ToString()+"_"+arrfileindex2[i].ToString();
" pb[i].height="120;
" lbl[i].width="60;
" lbl[i].height="15;
" pb[i].tag="arrfileindex1[i].ToString()+"_"+arrfileindex2[i].ToString();
" messagebox.show(pb[i,k].tag.tostring());
="" pb[i].sizemode="PictureBoxSizeMode.CenterImage;
" numberhorizontal="-1;
" if="" (numberhorizontal="" 0)
="" determine="" how="" many="" thumbnails="" can="" be="" displayed="" on="" one="" row
="" (this.panel2.width="" pb[i].width);
="" set="" the="" position="" for="" thumbnail="" and="" add="" it="" to="" panel's="" controls
="" pb[i].left="_margin" (pb[i].width+_margin)="" *="" ((this.panel2.controls.count="" 2)="" %="" (numberhorizontal-1));
="" pb[i].top="_margin" (pb[i].height+_margin)="" lbl[i].left="pb[i].Left" 60;
="" lbl[i].top="pb[i].Top" 120;
="" lbl[i].backcolor="Color.White;
" pb[i].click+="new" eventhandler(pictureclick);
="" pb[i].mousedown+="new" mouseeventhandler(picturemousedown);
="" pb[i].mousemove+="new" mouseeventhandler(picturemousemove);
="" pb[i].dragdrop+="new" drageventhandler(picturedragdrop);
="" pb[i].dragenter+="new" drageventhandler(picturedragenter);
="" pb[i].mouseup+="new" mouseeventhandler(picturemouseup);
="" pb[i].paint+="new" painteventhandler(imageview1_paint);
="" pb[i].allowdrop="true;
" pb[i].enabled="false;
" disable="" picturebox="" which="" are="" already="" linked
="" if(utils.globallink!="null)
//" tag="arrfileindex1[i].ToString()+"_"+arrfileindex2[i].ToString();
//" if(index!="-1)
//" lbl[i].mousemove+="new" mouseeventhandler(lblimageview_mousemove);
="" lbl[i].click+="new" eventhandler(lblimageview_click);
="" lbl[i].text="(arrfileindex1[i])" (arrfileindex2[i]);
="" this.panel1.controls.add(pb[i]);
="" this.panel1.controls.add(lbl[i]);
="" max="Math.Min(150," 120);
="" width="_image.Width;
" height="_image.Height;
" size="" image
="" (_image.width=""> max || _image.Height > max)
{
if (_image.Width > _image.Height)
{
width = max+15;
height = (int) (_image.Height * max / _image.Width)-10;
}
else
{
width = (int) (_image.Width * max / _image.Height)+15;
height = max-10;
}
}
pb[i].Image = new Bitmap(_image, width, height);
this.panel2.Controls.Add(pb[i]);
pb[i].SendToBack();
}
this.panel2.Controls.AddRange(lbl);
// this.panel1.Controls.AddRange(pb);
if((j%4)==0)
{
panel2.Height=(j/4)*150;
}
else
{
panel2.Height=(int)((j/4)*150+250);
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void pictureClick(object sender, System.EventArgs e)
{
panel1.Focus();
//pb[j].Tag=1;
// PictureBox who1=(PictureBox) sender;
// if(who1.Image!=null)
// {
// //who1.BackColor=Color.Black;
// m_MouseIsDown=false;
// utils.img = who1.Image;
// utils.imgname=who1.Tag.ToString();
// //MessageBox.Show(who1.Tag.ToString());
// actualimagesize frmAIS=new actualimagesize();
// frmAIS.ShowDialog();
//
//
//
// }
}
private void pictureMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
PictureBox who=(PictureBox) sender;
//MessageBox.Show(who.Tag.ToString());
if(who.Image!=null)
{
//Panel who1=(Panel) panel1;
//toolTip1.Dispose();
//MessageBox.Show(who.Tag.ToString());
linkfrom=who.Tag.ToString();
m_MouseIsDown=true;
//who.Focus();
//who.BackColor=Color.Tomato;
ps.X = e.X;
ps.Y = e.Y;
pe = ps;
string x=e.X.ToString();
string y=e.Y.ToString();
string coord=x+","+y;
if(startcoordinates==null)
{
startcoordinates=coord;
}
else
{
startcoordinates=startcoordinates+"#"+coord;
}
// panelmousedown=true;
}
}
private void pictureMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
PictureBox who=(PictureBox) sender;
//who.Cursor=Cursors.Hand;
//toolTip1.SetToolTip(who, "Click to view document full size. Drag the document to link it to another document");
if(m_MouseIsDown==true)
{
//code added on 12/21/2004 for backcolor of picturbox
if(hascolor==false)
{
Color c = new Color();
c=medappzDMS.utils.GetRandomColor();
pbcolor=c.Name;
hascolor=true;
}
// MessageBox.Show(pbcolor);
//who.BackColor=utils.getcolorname(pbcolor);
//code end 12/21/2004
who.DoDragDrop(who.Image, DragDropEffects.Move);
m_IsDragDrop=true;
}
m_MouseIsDown=false;
}
private void pictureDragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if(e.Data.GetDataPresent(DataFormats.Bitmap))
{
//Check for the CTRL key.
if(e.KeyState == 9)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.Move;
}
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void pictureDragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
if(m_IsDragDrop==true)
{
PictureBox who=(PictureBox) sender;
//code 12/21/2004
//who.BackColor=utils.getcolorname(pbcolor);
//DrawLineInt(who);
//code end 12/21/2004
string linkto=who.Tag.ToString();
//MessageBox.Show(who.Tag.ToString());
if(linkfrom==linkto)
{
//who.BackColor=Color.Black;
m_MouseIsDown=false;
utils.img = who.Image;
utils.imgname=who.Tag.ToString();
actualimagesize frmAIS=new actualimagesize();
frmAIS.ShowDialog();
}
else
{
if(locallink==null)
{
locallink=linkfrom+","+linkto;
// MessageBox.Show(locallink);
lblviewcurlinks.Text=locallink;
}
else
{
int index=locallink.IndexOf(linkto);
int index1=locallink.IndexOf(linkfrom);
if((index==-1)&&(index1==-1))
{
locallink+=","+linkfrom+","+linkto;
// MessageBox.Show(locallink);
lblviewcurlinks.Text=locallink;
}
else if((index==-1)&&(index1!=-1))
{
locallink+=","+linkto;
// MessageBox.Show(locallink);
lblviewcurlinks.Text=locallink;
}
else if((index!=-1)&&(index1==-1))
{
locallink+=","+linkfrom;
// MessageBox.Show(locallink);
lblviewcurlinks.Text=locallink;
}
else
{
// MessageBox.Show(locallink);
lblviewcurlinks.Text=locallink;
}
}
}
Panel thisform = (Panel) panel1;
// First DrawReversible to toggle to the background color
// Second DrawReversible to toggle to the specified color
ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
pe.X = e.X;
pe.Y = e.Y;
string x=e.X.ToString();
string y=e.Y.ToString();
string coord=x+","+y;
if(endcoordinates==null)
{
endcoordinates=coord;
}
else
{
endcoordinates=endcoordinates+"#"+coord;
}
//ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
//Panel thisform = (Panel)sender;
Graphics g = thisform.CreateGraphics();
Pen p = new Pen(Color.Blue, 2);
//ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
g.DrawLine(p, ps, pe);
g.Dispose();
}
//btnstop.Enabled=true;
m_IsDragDrop=false;
}
public void DrawLineInt(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
}
private void imageview1_Paint(object sender, PaintEventArgs e)
{
}
private void pictureMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
// if (e.Button==MouseButtons.Left)
// {
//
// Panel thisform = (Panel) panel1;
//
// // First DrawReversible to toggle to the background color
// // Second DrawReversible to toggle to the specified color
// ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
// pe.X = e.X;
// pe.Y = e.Y;
// string x=e.X.ToString();
// string y=e.Y.ToString();
// string coord=x+","+y;
// if(endcoordinates==null)
// {
// endcoordinates=coord;
// }
// else
// {
// endcoordinates=endcoordinates+"#"+coord;
// }
// ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
//
//
//
// //Panel thisform = (Panel)sender;
// Graphics g = thisform.CreateGraphics();
// Pen p = new Pen(Color.Blue, 2);
//
// ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
// g.DrawLine(p, ps, pe);
//
// g.Dispose();
// }
}
private void fmlinks_Load(object sender, System.EventArgs e)
{
DisplayThumbnails();
}
private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
for (int i=0; i< panel1.Controls.Count; i++)
{
if(panel1.Controls[i].Focused==true)
{
//panel1.Controls[i].Enabled=true;
MessageBox.Show(panel1.Controls[i].Tag.ToString());
}
}
ps.X = e.X + panel1.AutoScrollHPos;
ps.Y = e.Y + panel1.AutoScrollVPos;
pe = ps;
string x=e.X.ToString();
string y=e.Y.ToString();
string coord=x+","+y;
//MessageBox.Show(panel1.AutoScrollPosition.X.ToString()+" "+panel1.AutoScrollPosition.Y.ToString());
if(startcoordinates==null)
{
startcoordinates=coord;
}
else
{
startcoordinates=startcoordinates+"#"+coord;
}
// panelmousedown=true;
}
private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// if (e.Button==MouseButtons.Left)
// {
// if(panelmousedown==true)
// {
// Panel thisform = (Panel)sender;
//
// First DrawReversible to toggle to the background color
// Second DrawReversible to toggle to the specified color
// ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
// pe.X = e.X;
// pe.Y = e.Y;
// string x=e.X.ToString();
// string y=e.Y.ToString();
// string coord=x+","+y;
// if(endcoordinates==null)
// {
// endcoordinates=coord;
// }
// else
// {
// endcoordinates=endcoordinates+"#"+coord;
// }
// ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
//
// }
// panelmousedown=false;
//}
}
private void panel1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button==MouseButtons.Left)
{
Panel thisform = (Panel)sender;
// First DrawReversible to toggle to the background color
// Second DrawReversible to toggle to the specified color
ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
pe.X = e.X + panel1.AutoScrollHPos;
pe.Y = e.Y + panel1.AutoScrollVPos;
string x=e.X.ToString();
string y=e.Y.ToString();
string coord=x+","+y;
if(endcoordinates==null)
{
endcoordinates=coord;
}
else
{
endcoordinates=endcoordinates+"#"+coord;
}
ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
//Panel thisform = (Panel)sender;
Graphics g = thisform.CreateGraphics();
Pen p = new Pen(Color.Blue, 2);
ControlPaint.DrawReversibleLine(thisform.PointToScreen(ps), thisform.PointToScreen(pe), Color.Black);
g.DrawLine(p, ps, pe);
g.Dispose();
MessageBox.Show(startcoordinates);
}
}
private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//this.panel1.SuspendLayout();
}
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Panel thisform = (Panel)sender;
Graphics g = thisform.CreateGraphics();
Pen p = new Pen(Color.Blue, 2);
if((startcoordinates!=null)||(endcoordinates!=null))
{
char[] charfileindex1;
charfileindex1=new char[]{'#'};
char[] charfileindex2;
charfileindex2=new char[]{'#'};
int charfileindexlen1=startcoordinates.Split(charfileindex1).Length;
string[] ss=new string[charfileindexlen1];
ss=startcoordinates.Split(charfileindex1);
string[] ss1=new string[charfileindexlen1];
ss1=endcoordinates.Split(charfileindex1);
for(int i=0; i
|
|
|
|
|
The way I told you is best. It has the least amount of overhead (only one control is needed instead of two), you can overlap the line with the pictures, and instead of handling events for three controls you're only handling events for one control by overriding the event handlers (OnEventName methods). This is simple owner drawing. I could certainly do it in a lot less lines and with more control than what you have above.
Take a look at the Graphics.DrawImage overloads. They're easy to use and will draw the image for you at the specified location (and even stretch them and apply optional matrix transformations).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
But the thing is i dont have just two images, i have images coming from a folder and their nuumber can vary and need to be placed systematically on a panel and then i need to draw lines between them. Is it possible in the way you have told me, please let me know.
Thanks
Nitin
|
|
|
|
|
So instead of calling Graphics.DrawImage twice call it as many times as you need. It's no different conceptually than instantiating X number of PictureBox es, siting those in your container control, and loading images into them. The biggest differences between drawing the images yourself and using PictureBox controls is that PictureBox controls have more overhead (they're controls - not just an image) and aren't as flexible as drawing the images yourself. Like I said before, if you want your line to overlap the images you either need to use layered windows (not easy - requires that you P/Invoke a could of native methods, define constants from various Windows APIs headers, and a couple of structs that are defined natively) or draw it all on the same surface. It's really not that hard.
Again, read the documentation for the Graphics class which has a lot of examples for owner-drawing as well.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|