Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
Resources » Code Snippets » C# Syntax »
Adding Vertex points to Control
|
This class will add the Vertex points to the Label Control Image
#region Namespace Declaraion
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using System.Resources; using System.Collections;
#endregion
namespace Common {
#region Classes
/// /// To Select the Element on BPMapCanvas with VertexPoints /// To Move the Element on BPMapCanvas with MouseMovement /// While moving placing a copy of Element at its Initial Position /// Removing the Copy Element when Moving Completes /// public class VortexToControl {
#region Class Level Declarations
/// /// For Creating Vertex and Border to the Control /// private Graphics g;
/// /// To Persist Mouse Left Location Before Moving the Control /// private int StartX = 0;
/// /// To Persist Mouse Top Location Before Moving the Control /// private int StartY = 0;
/// /// To Persisit Start Left Location of the Control Before Moving /// So that if the Control is OverLapped it will bring back to its previous Left position /// private int StartLocX = 0;
/// /// To Persisit Start Top Location of the Control Before Moving /// So that if the Control is OverLapped it will bring back to its previous Top position /// private int StartLocY = 0;
/// /// Size of the VertexPoint Rectangles /// Later it is taken from Options that is provided for this Project /// private const int VertexSize = 5;
/// /// Corner Vertex Point Rectangles /// private Rectangle VertexRec1, VertexRec2, VertexRec3, VertexRec4;
/// /// Middle Vertex point Rectangles /// private Rectangle VertexRec5, VertexRec6, VertexRec7, VertexRec8;
/// /// Tag for SingleSelection Copy Control /// So that it is possible to remove it when original element moving completes /// This can be any value. /// this is used only to recognize the Copy of the Element Moving /// protected const long SingleSelectionTag = 82810316;
/// /// BackColor for Copy of the Element /// Later it is taken from Options that is provided for this Project /// private Color CopyControlBackColor = Color.LightSteelBlue;
/// ///Color for Border of the Image in Selected Element ///Later it is taken from Options that is provided for this Project /// private Color BorderColor = Color.Orange;
/// /// Color for the Border of VertexRectangles ///Later it is taken from Options that is provided for this Project /// private Color VertexRectangleColor = Color.DarkOliveGreen; /// /// For persisting the ActiveBPMapCanvas /// private Form BPMapCanvasform = null;
/// /// For Persisitng Selected Control on BPMapCanvas /// public Control SelectedControl;
/// /// To persist the Elements that are selected /// private ArrayList SelectedElements = new ArrayList();
/// /// To persist the state of Multi Selection of Elements. /// True represents the existance of MultiSelection on BPMapCanvas /// private bool IsMultiElementsSelected = false;
/// /// This is used to move the MultiSelected elements /// Need to change later. /// private int CounterForMouseMove = 0;
/// /// To store the start positions of Elements that are in MultiSlection before they are moving. /// If the Elements are overlapped then they are bring back to start postions by using ht evaues in this HashTable /// private Hashtable htblElementsStartPositions = new Hashtable(); /// /// /// private IBPMapCanvas ObjIBPMapCanvas;
/// /// /// private IPropertyWindow ObjPropertyWindow;
#endregion
#region Properties
/// /// To Store the reference of Elements that are in Multi Selection /// public ArrayList MultiSelectedElements { get { return SelectedElements; } set { SelectedElements = value; } }
/// /// To Store the Status of Multi Selection /// public bool IsMultiSelection { get { return IsMultiElementsSelected; } set { IsMultiElementsSelected = value; } }
#endregion
#region Control Evenets
/// /// To Select the Control with VertexPoints. /// To Create a Copy of the Control. /// /// /// public void Control_MouseDown(Control ControlSelected, MouseEventArgs e) { try { //If the Selected Control is not the IBPElement then return the Excution control if (!(ControlSelected is IBPElement)) { return;
}//End od if
//If the Element is Selected Using Control Key and Left MouseButton //Then there is need of MultiSelection if (e.Button == MouseButtons.Left && System.Windows.Forms.Control.ModifierKeys == Keys.Control) { //If the Image of Element does not Contains the Tag //menas Element is not Selected so Select the Element if (((IBPElement)ControlSelected).IsSelected == false) { //As Control key is pressed set the MultiSelection Flag to True IsMultiElementsSelected = true; //If the arraylist of MultiSelected Elements does not contains //the Current element add the Element to list if (!(SelectedElements.Contains(ControlSelected))) { SelectedElements.Add(ControlSelected);
}//End of if
//Select The Element with vertex points SelectControl(ControlSelected);
}//End of if //If the Element is already selected then as the Control key is pressed //Deselect the Control and Remove from the list else { SelectedElements.Remove(ControlSelected); DeSelectControl(ControlSelected); ((IBPElement)ControlSelected).IsSelected = false;
}//End of else }//End of if
//If only Left Mouse Button Clicked then it is only for Single Selection else if (e.Button == MouseButtons.Left) { //If there exists the Multi Selection //Clear values in HashTable and Store the new Start positions of Multi Selected Elements if (IsMultiElementsSelected == true) { htblElementsStartPositions.Clear(); StoreStartPositionsOfElements();
}//End of if
//If there is no Multi Selection else {
//If the Array List does not Contains the Element //Selecting an Unselected Control if (!(SelectedElements.Contains(ControlSelected))) { //Deselect the Remaining Controls on BPMapCanvas before Selecting a new Control DeSelectAll(BPMapCanvasform); //Clear the Selected elements list SelectedElements.Clear(); //Add the control to Selected Elements list SelectedElements.Add(ControlSelected); //Change the multi Selection state to false IsMultiElementsSelected = false;
//call the Release Multiple selection method to remove the MultiSelection if exists if (((IBPMapCanvas)BPMapCanvasform).MultiSelection.IsMultiSelection == true) { ((IBPMapCanvas)BPMapCanvasform).MultiSelection.ReleaseMultipleSelection((Form)BPMapCanvasform);
}//End of if
//Change the Cursor of the Control to Size all so that it will represent that the Element location can be changed ControlSelected.Cursor = Cursors.SizeAll;
//Select the Control with vertexpoints SelectControl(ControlSelected);
//persist the Start Location of the Element so that if the Control is overlapped while changing position //It will placed to its original start Location StartLocX = ControlSelected.Location.X; StartLocY = ControlSelected.Location.Y;
}//End of if
//Create the Copy of the Control so that it will be at the starting position of the Control CreateCopyOfControl(ControlSelected);
}//End of else
}//End of else if
//Persist the Start Mouse locations StartX = e.X; StartY = e.Y; //Change the Cursor to Size All to represent Selection And Moving ControlSelected.Cursor = Cursors.SizeAll;
//If the MultiSelected Elements List contains less than or equal to one //That means only one control is selected //Set the MultiSelection flag to false if (SelectedElements.Count == 0) { IsMultiElementsSelected = false; //UIScreen.BPDPropertiesWindow.RefreshElementCombobox(); ObjPropertyWindow.RefreshElementCombobox();
}//End of if //If the array list contains only one element else if (SelectedElements.Count == 1) { //Set the multiSelection flag to false as there is only one element selected IsMultiElementsSelected = false; IBPElement SelectedControl = (IBPElement)SelectedElements[0]; //Select the Element by setting the IsSelected Property to true. ((IBPMapCanvas)BPMapCanvasform).SelectBPElement(SelectedControl); //If there is single control selected then show the properties of the control in property grid //UIScreen.BPDPropertiesWindow.SetSelectedObject(SelectedControl.GetElementProperties); ObjPropertyWindow.RefreshElementCombobox();
}//End of else if //If the Array List conatins more than one element else { //Deselect all the Elements by setting the IsSelected property to false ((IBPMapCanvas)BPMapCanvasform).DeselectAllBPElements(); //Property window should not show any properties for MultiSlection //So Set the Selected Object to null //UIScreen.BPDPropertiesWindow.SetSelectedObject(null); //Refresh the PropertyElement combobox to show nothing ObjPropertyWindow.RefreshElementCombobox();
}//End of else
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void Control_MouseDown(Control, MouseEventArgs) /// /// To Move the Selected Control with MouseMove. /// If the Control is Overlapped Change the Cursor to NO /// /// /// public void Control_MouseMove(Control ControlSelected, MouseEventArgs e) {
try { //If the Control is not IBPElement return if (!(ControlSelected is IBPElement)) { return;
}//End of if
//Is Left Mouse Button Cliked and Control key is not pressed if (e.Button == MouseButtons.Left && System.Windows.Forms.Control.ModifierKeys != Keys.Control) { //If there is multi Selection if (IsMultiElementsSelected == true) { CounterForMouseMove++;
//This is added by Uday Denduluri.
if (CounterForMouseMove > 2) { //Move all the Elements which are in Multi Selection //While Moving check the Overlapping of Elements for (int Iteration = 0; Iteration < SelectedElements.Count; Iteration++) { Control CurrentControl = (Control)SelectedElements[Iteration]; //If the control is overlapped on another control then change the cursor to No and else to SizeAll if (IsControlOverlapped(CurrentControl) == true) { ControlSelected.Cursor = Cursors.No;
}//End of if else { ControlSelected.Cursor = Cursors.SizeAll;
}//End of else
//Calculate the new Location of the Control with Mouse Move //Logic for Getting the Current Location //Location =(Current Control location + Current Mouse Location - Previous Mouse Down Location) int l = CurrentControl.Left + e.X - StartX; int t = CurrentControl.Top + e.Y - StartY;
//To Check wehther the control is moved out of Left and Top positions of the BPMapCanvas //If the Control is Moving out of range of Left and Top margins of BPMapCanvas Change the Location to (0,0) l = (l < 0) ? 0 : l; t = (t < 0) ? 0 : t;
//New Location of the Control CurrentControl.Left = l; CurrentControl.Top = t; CounterForMouseMove = 0;
}//End of for
}//End of if
}//End of if //If there is no multiSelection move the Single Element //Check the Overlapping of Element with Other Elements on BPMapCanvas else {
//If the control is overlapped on another control then change the cursor to No and else to SizeAll if (IsControlOverlapped(ControlSelected) == true) { ControlSelected.Cursor = Cursors.No;
}//End of if
//To Change the Cursor to No when Control is moved Out of Left and Top Margins of the BPMapCanvas else if (e.X < BPMapCanvasform.DisplayRectangle.Left || e.Y < BPMapCanvasform.DisplayRectangle.Top) { ControlSelected.Cursor = Cursors.No;
}//End of if else { ControlSelected.Cursor = Cursors.SizeAll;
}//End of else
//Calculate the new Location of the Control with Mouse Move //Logic for Getting the Current Location //Location =(Current Control location + Current Mouse Location - Previous Mouse Down Location) int l = ControlSelected.Left + e.X - StartX; int t = ControlSelected.Top + e.Y - StartY;
//To Check wehther the control is moved out of Left and Top positions of the BPMapCanvas //If the Control is Moving out of range of Left and Top margins of BPMapCanvas Change the Location to (0,0) l = (l < 0) ? 0 : l; t = (t < 0) ? 0 : t;
//New Location of the Control ControlSelected.Left = l; ControlSelected.Top = t; ControlSelected.BringToFront();
}//End of else if
}//Edn of if
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void Control_MouseMove(Control, MouseEventArgs)
/// /// To Stop the Control Movement. /// Dispose the Copy of the Actual Control. /// /// /// public void Control_MouseUp(Control ControlSelected, MouseEventArgs e) {
try { //To Stop the Movement of Control and to change the Cursor to Default. ControlSelected.Cursor = Cursors.Default;
//If there exists multi Selection check the Ovelapping of Elements if (IsMultiElementsSelected == true) { //Check overlapping for all elements in Multi Selection for (int Iteration = 0; Iteration < SelectedElements.Count; Iteration++) { Control CurrentControl = (Control)SelectedElements[Iteration]; CurrentControl.Cursor = Cursors.Default; //if the Element is overlapped then move the Elements back to their start position if (IsControlOverlapped(CurrentControl) == true) { ReplaceElemntsLocationToStartPosition();
}//End of if
}//End of for
}//End of if
//If there is no multi Selection then check the overlapping of Element else { //if the Control is overlapped then place the Control at its original position if (IsControlOverlapped(ControlSelected) == true) { //To avoid the blur make the control visible false first and later make the visible as true ControlSelected.Visible = false; //change the location of control to Start position ControlSelected.Left = StartLocX; ControlSelected.Top = StartLocY;
//Make the visible true which is set to false before to avoid blur ControlSelected.Visible = true;
}//End of if
//Dispose the Copy of the original Control by checking the Tag property of Control foreach (Control control in BPMapCanvasform.Controls) { if (control.GetType().FullName == "System.Windows.Forms.Label" && (long)control.Tag == SingleSelectionTag) { control.Dispose();
}//End of if
}//End of foreach
ControlSelected.SendToBack(); //To refresh the Property Window with New Location of Control ObjPropertyWindow.GetPropertyGrid().Refresh();
}//End of else
}//End of try //To handle NullReference exception when PropertyGrid is null catch (NullReferenceException ObjNullReferenceException) { throw ObjNullReferenceException; }//End of catch
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void Control_MouseUp(Control, MouseEventArgs)
#endregion
#region Methods
/// /// TO Select the Control from the PropertyWindow. /// /// public void SelectFromProperty(Control ControlSelected) { try { //If the Control is not the IBPElement then return the execution control if (!(ControlSelected is IBPElement)) { return;
}//End of if
//if the Control is selected from property window comboBox //Clear the MultiSelected Elements list. //Add the selected control to list ((IBPMapCanvas)BPMapCanvasform).MultiSelection.MultiSelectedElementsList.Clear(); ((IBPMapCanvas)BPMapCanvasform).MultiSelection.MultiSelectedElementsList.Add(ControlSelected);
SelectedElements.Clear(); SelectedElements.Add(ControlSelected); //TO Select control When it is Selected from Property Window SelectControl(ControlSelected);
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch }// End of Select(Control, MouseEventArgs)
/// /// Getting the Form that creates instance of this class /// /// frm represents the Active BPMapCanvas public void GetForm(Form frm) { try { //TO Get the Active BPMapCanvas BPMapCanvasform = frm;
}//End of try
catch (BPDBaseException) { throw;
}//End of catch //As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void GetForm(Form)
/// /// To Create the Copy of the Actual Control when MouseDown Occurs on it. /// So that it is placed at the Starting location of the Control to show the original location /// /// private void CreateCopyOfControl(Control ControlSelected) { try { //Create a label and append the properties of Original control to Copy Control. Label CopyLabel = new Label(); CopyLabel.Width = ControlSelected.Width; CopyLabel.Height = ControlSelected.Height; CopyLabel.Location = ControlSelected.Location; CopyLabel.BackColor = CopyControlBackColor; CopyLabel.ForeColor = ControlSelected.ForeColor; CopyLabel.Text = ControlSelected.Text; CopyLabel.Font = ControlSelected.Font; //CopyLabel.Image = ((Label)ControlSelected).Image; CopyLabel.TextAlign = ((Label)ControlSelected).TextAlign; //CopyLabel.ImageAlign = ((Label)ControlSelected).ImageAlign; CopyLabel.MinimumSize = ControlSelected.MinimumSize;
PictureBox PicBox = new PictureBox(); foreach (Control ctrl in ControlSelected.Controls) { if (ctrl is PictureBox) { PicBox.Image = ((PictureBox)ctrl).Image; PicBox.Size = ctrl.Size; PicBox.SizeMode = PictureBoxSizeMode.StretchImage; PicBox.Location = ctrl.Location; CopyLabel.Controls.Add(PicBox);
}//End of if
}//End of foreach
//Add Tag property to it to recognize the control later CopyLabel.Tag = SingleSelectionTag;
//Checking for BPMapCanvas Existance if (BPMapCanvasform != null) { //Add the Copy Control to BPMapCanvas. BPMapCanvasform.Controls.Add(CopyLabel); }//End of if
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of private void CreateCopyOfControl(Control)
/// /// Creating VertexPoints to the Control /// /// public void SelectControl(Control ControlSelected) { try { // this Code is added by Uday Denduluri // returning the Control if the selected control is not of type IBPElement //Checking for IBPElement if (!(ControlSelected is IBPElement)) { return; }//End of try // this Code is added by Uday Denduluri //Make the Control as SelectedControl SelectedControl = ControlSelected;
//If the control is already selected then simply return if (ControlSelected.Tag != null) { return; }
//Bitmap for Holding the Image of the BPElement Bitmap LabelImage = null; PictureBox pcbox = null; ; //Get the Picturebox from the BPElement foreach (Control ctl in ControlSelected.Controls) { if (ctl is PictureBox) { pcbox = (PictureBox)ctl; //Getting the Image to Bitmap And assigning the bitmap to Control Tag ControlSelected.Tag = pcbox.Image; LabelImage = new Bitmap(pcbox.Image, new Size(pcbox.Width, pcbox.Height));
}//End of if
}//End of foreach
//If there is no picturebox in Element then return if (pcbox == null) { return;
}//End of if
//If the Image of the BPElement is null then return if (LabelImage == null) { return;
}//End of if
//To draw the Border across the Image inside the Control and //Vertex points across the image. g = Graphics.FromImage(LabelImage);
//Calculations for Image Width and Height int imgwidth = pcbox.Width; int imgheight = pcbox.Height;
//Rectangle to draw the Border across the Image of the Control Rectangle BorderRec = new Rectangle(0, 0, imgwidth, imgheight);
//Vertex Rectangles at the Borders of the Image // Four rectangles are taken initially to shown the 4 vertex points of the rectangle VertexRec1 = new Rectangle(0, 0, VertexSize, VertexSize); VertexRec2 = new Rectangle(LabelImage.Width - VertexSize, 0, VertexSize, VertexSize); VertexRec3 = new Rectangle(0, LabelImage.Height - VertexSize, VertexSize, VertexSize); VertexRec4 = new Rectangle(LabelImage.Width - VertexSize, 0 + LabelImage.Height - VertexSize, VertexSize, VertexSize);
//Vertex Rectangles at the Middle of the Image // Four rectangles are now taken to shown the 4 points between vertex points of the rectangle VertexRec5 = new Rectangle((LabelImage.Width / 2) - (VertexSize / 2), 0, VertexSize, VertexSize); VertexRec6 = new Rectangle(0, (LabelImage.Height / 2) - (VertexSize / 2), VertexSize, VertexSize); VertexRec7 = new Rectangle(LabelImage.Width - VertexSize, (LabelImage.Height / 2) - (VertexSize / 2), VertexSize, VertexSize); VertexRec8 = new Rectangle((LabelImage.Width / 2) - (VertexSize / 2), LabelImage.Height - VertexSize, VertexSize, VertexSize);
//Drawing the VertexPoint Rectangles to the Iamge of the Control ControlPaint.DrawBorder(g, VertexRec1, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec2, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec3, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec4, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec5, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec6, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec7, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec8, VertexRectangleColor, ButtonBorderStyle.Solid);
//Placing Border to the Iamge of Control ControlPaint.DrawBorder(g, BorderRec, BorderColor, ButtonBorderStyle.Dashed);
//Fill the VertexPoint rectangles with Color FillVertexPoints(); //Assign the New Image to the Element pcbox.Image = LabelImage;
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void SelectControl(Control)
/// /// To Fill the VertexPoint Rectangles with Specified Color. /// private void FillVertexPoints() { try { //Fill the Rectangles with Color Brush b = new SolidBrush(VertexRectangleColor);
//Code Added By Uday Denduluri if (VertexRec1.IsEmpty) return; if (VertexRec2.IsEmpty) return; if (VertexRec3.IsEmpty) return; if (VertexRec4.IsEmpty) return; if (VertexRec5.IsEmpty) return; if (VertexRec6.IsEmpty) return; if (VertexRec7.IsEmpty) return; if (VertexRec8.IsEmpty) return; //Code Added By Uday Denduluri g.FillRectangle(b, VertexRec1); g.FillRectangle(b, VertexRec2); g.FillRectangle(b, VertexRec3); g.FillRectangle(b, VertexRec4); g.FillRectangle(b, VertexRec5); g.FillRectangle(b, VertexRec6); g.FillRectangle(b, VertexRec7); g.FillRectangle(b, VertexRec8);
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void FillVertexPoints()
/// /// To DeSelect the Single Control which is Already Selected /// /// public void DeSelectControl(Control ControlSelected) { try { // Code Added By Uday Denduluri if (!(ControlSelected is IBPElement)) { return;
}//End of if
// Code Added by Uday Denduluri //If Control is IBPElement then Deselect the Control if (ControlSelected.Tag != null) { Image img = (Image)ControlSelected.Tag; if (img == null) { return; }//End of if foreach (Control ctl in ControlSelected.Controls) { if (ctl is PictureBox) { //Add the Original Image to the BPElement ((PictureBox)ctl).Image = img;
}//End of if
}//End of foreach
//To Show it as Deseleted Element ControlSelected.Tag = null; }//End of if
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch }//End of public void DeSelectControl(Label)
/// /// To DeSelect All the Controls that are selected On the BPMapCanvas /// /// form is the reference of the current BPMap Canvas public void DeSelectAll(Form form) { try { //Repeating the DeselctControl Method for all the Controls on BPMapCanvas foreach (Control ctl in form.Controls) { if (ctl is IBPElement) { //If the Control is IBPElement then only it will Deselects and Its Image.Tag property exists if (ctl.Tag != null) { DeSelectControl(ctl);
}//End of if
}//End of if
}//End of foreach
//Set the Selected control to null as All the Controls are deselected. //BPMapCanvasform.VortexControl.SelectedControl = null; this.SelectedControl = null;
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void DeSelectAll(Form)
/// /// To Avoid the Overlapping of the Controls on BPMapCanvas. /// It will return true if Control is Overlapped /// It will return false if the control is not overlapping /// /// /// public bool IsControlOverlapped(Control ControlSelected) { try { //To Persist the Bounds of Moving Control on BPMapCanvas int CtlLocX = ControlSelected.Location.X; int CtlLocY = ControlSelected.Location.Y; int CtlWidth = ControlSelected.Width; int CtlHeight = ControlSelected.Height;
//Check the Overlapping of Moving Control with All IBPElements on BPMapCanvas foreach (Control ControlOnCanvas in BPMapCanvasform.Controls) { //If the Control on BPMApCanvas is IBPElement then check for Overlap if (ControlOnCanvas is IBPElement) { if (ControlSelected != ControlOnCanvas) { //To persist the Bounds of Element on BPMapCanvas int ElementLocX = ControlOnCanvas.Location.X; int ElementLocY = ControlOnCanvas.Location.Y; int ElementWidth = ControlOnCanvas.Width; int ElementHeight = ControlOnCanvas.Height; //If the Checked Control on BPMapCanvas is IBPElement then check if (ControlOnCanvas != ControlSelected && ControlOnCanvas.Tag == null) { //Checking for Right upper Corner OverLap of Moving Element if ((ElementLocX <= CtlLocX && CtlLocX <= (ElementWidth + ElementLocX)) && (ElementLocY <= CtlLocY && CtlLocY <= (ElementHeight + ElementLocY))) { return true;
} //End of if
//Chacking for Left upperCorner Overlap of Moving Element if ((ElementLocX <= (CtlLocX + CtlWidth) && (CtlLocX + CtlWidth) <= (ElementLocX + ElementWidth)) && (ElementLocY <= CtlLocY && CtlLocY <= (ElementLocY + ElementHeight))) { return true;
} //End of if
//Chacking for Right BottomCorner Overlap of Moving Element if ((ElementLocX <= CtlLocX && CtlLocX <= (ElementLocX + ElementWidth)) && (ElementLocY <= (CtlLocY + CtlHeight) && (CtlLocY + CtlHeight) <= (ElementLocY + ElementHeight))) { return true;
} //End of if
//Chacking for Left BottomCorner Overlap of Moving Element if ((ElementLocX <= (CtlLocX + CtlWidth) && (CtlLocX + CtlWidth) <= (ElementLocX + ElementWidth)) && (ElementLocY <= (CtlLocY + CtlHeight) && (CtlLocY + CtlHeight) <= (ElementLocY + ElementHeight))) { return true;
} //End of if
//If the Moving Control width is Greater that the Element on BPMapCanvas then Check for Full OverLap if (CtlWidth > ElementWidth) { if ((CtlLocX <= ElementLocX) && (ElementLocX <= (CtlLocX + CtlWidth)) && (((CtlLocY <= ElementLocY) && (ElementLocY <= (CtlLocY + CtlHeight))) || ((CtlLocY <= (ElementLocY + ElementHeight)) && ((ElementLocY + ElementHeight) <= (CtlLocY + CtlHeight))))) { return true;
} //End of if
}//End of if
}//End of if
}//End of if
}//End of if
}//End of foreach
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
// if none of the condition for the above gets satisfied then return false. // This means that there is no Overlap return false;
}//End of private bool IsControlOverlapped(Control)
/// /// To Select the Last Control in the MultiSelection without Filling VertexPoint rectangles /// /// Here Control is IBPElement public void SelectLastControl(Control ControlSelected) { try { // this Code is added by Uday Denduluri // returning the Control if the selected control is not of type IBPElement //Checking for IBPElement if (!(ControlSelected is IBPElement)) { return;
}//End of try
//Make the Control as SelectedControl SelectedControl = ControlSelected;
//If the control is already selected then simply return if (ControlSelected.Tag != null) { return; }
//Bitmap for Holding the Image of the BPElement Bitmap LabelImage = null; PictureBox pcbox = null; ; //Get the Picturebox from the BPElement foreach (Control ctl in ControlSelected.Controls) { if (ctl is PictureBox) { pcbox = (PictureBox)ctl; //Getting the Image to Bitmap And assigning the bitmap to Control Tag ControlSelected.Tag = pcbox.Image; LabelImage = new Bitmap(((PictureBox)ctl).Image, new Size(pcbox.Width, pcbox.Height));
}//End of if }//End of foreach
//If there is no picturebox in Element then return if (pcbox == null) { return;
}//End of if
//If the Image of the BPElement is null then return if (LabelImage == null) { return;
}//End of if //To draw the Border across the Image inside the Control and //Vertex points across the image. g = Graphics.FromImage(LabelImage);
//Calculations for Image Width and Height int imgwidth = pcbox.Width; int imgheight = pcbox.Height;
//Rectangle to draw the Border across the Image of the Control Rectangle BorderRec = new Rectangle(0, 0, imgwidth, imgheight);
//Vertex Rectangles at the Borders of the Image // Four rectangles are taken initially to shown the 4 vertex points of the rectangle VertexRec1 = new Rectangle(0, 0, VertexSize, VertexSize); VertexRec2 = new Rectangle(LabelImage.Width - VertexSize, 0, VertexSize, VertexSize); VertexRec3 = new Rectangle(0, LabelImage.Height - VertexSize, VertexSize, VertexSize); VertexRec4 = new Rectangle(LabelImage.Width - VertexSize, 0 + LabelImage.Height - VertexSize, VertexSize, VertexSize);
//Vertex Rectangles at the Middle of the Image // Four rectangles are now taken to shown the 4 points between vertex points of the rectangle VertexRec5 = new Rectangle((LabelImage.Width / 2) - (VertexSize / 2), 0, VertexSize, VertexSize); VertexRec6 = new Rectangle(0, (LabelImage.Height / 2) - (VertexSize / 2), VertexSize, VertexSize); VertexRec7 = new Rectangle(LabelImage.Width - VertexSize, (LabelImage.Height / 2) - (VertexSize / 2), VertexSize, VertexSize); VertexRec8 = new Rectangle((LabelImage.Width / 2) - (VertexSize / 2), LabelImage.Height - VertexSize, VertexSize, VertexSize);
//Drawing the VertexPoint Rectangles to the Iamge of the Control ControlPaint.DrawBorder(g, VertexRec1, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec2, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec3, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec4, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec5, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec6, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec7, VertexRectangleColor, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, VertexRec8, VertexRectangleColor, ButtonBorderStyle.Solid);
//Placing Border to the Iamge of Control ControlPaint.DrawBorder(g, BorderRec, BorderColor, ButtonBorderStyle.Dashed);
//Assign the New Image to the Picturebox of the BPElement pcbox.Image = LabelImage;
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void SelectControl(Label)
/// /// To store the Starting Location of the Elements that are in MultiSelection /// private void StoreStartPositionsOfElements() { if (SelectedElements.Count <= 1 || SelectedElements == null) { return;
}//End of if else { for (int Iteration = 0; Iteration < SelectedElements.Count; Iteration++) { Control CurrentControl = (Control)SelectedElements[Iteration]; htblElementsStartPositions.Add(CurrentControl, CurrentControl.Location);
}//End of for
}//End of else
}//End of private void StoreStartPositionsOfElements()
/// /// To Replace the Elements to their Start Positions if there is MultiSelection /// and atleast one Element in MultiSelection is Overlapped with Other Element /// private void ReplaceElemntsLocationToStartPosition() { if (SelectedElements.Count <= 1 || SelectedElements == null) { return;
}//End of if else { for (int Iteration = 0; Iteration < SelectedElements.Count; Iteration++) { Control CurrentControl = (Control)SelectedElements[Iteration]; Point StartPoint = (Point)htblElementsStartPositions[CurrentControl]; CurrentControl.Location = StartPoint;
}//End of for
}//End of else
}//End of private void ReplaceElemntsLocationToStartPosition()
#endregion
#region Constructors
/// /// /// /// public VortexToControl(IBPMapCanvas ObjIBPMapCanvasFromBPMap) { this.ObjIBPMapCanvas = ObjIBPMapCanvasFromBPMap; BPMapCanvasform = (Form)ObjIBPMapCanvas; ObjPropertyWindow = ObjIBPMapCanvas.ObjUIScreen.GetPropertyWindow(); }
/// /// /// public VortexToControl() {
}
#endregion
}// End of public class VortexToControl
/// /// To Select multiple Controls and to Move those controls on BPMapCanvas /// To Copy the Multiple selected controls to the ClipBoard. /// To Delete and Cut the MultiSelected Controls. /// public class MultipleSelectionControl {
#region Class Level Declarations
/// /// Instance of VortexToControl Class /// Inorder to use DeselectAll, SelectControl, SelectLastControl Methods /// //private VortexToControl CntrlVertex;
/// /// To persist the Width of MultiSelection Rectangle /// private int diffX = 0;
/// /// To persist the Height of MultiSelection Rectangle /// private int diffY = 0;
/// /// To Persist the Start Left Location of MultiSelection Panel /// To replace the MultiSelection panel back to previous position when overlapping occurs /// private int MultiStartX = 0;
/// /// To Persist the Start Top Location of MultiSelection Panel /// To replace the MultiSelection panel back to previous position when overlapping occurs /// private int MultiStartY = 0;
/// /// To persist wehther the Multi Selection is Valid or not /// protected bool IsMultiDrag = false;
/// /// Size of the VertexPoints of MultiSelection panel /// Later it can be Taken from Options Provided in the Project /// private int MultiVertexSize = 3;
/// /// To persist MouseDown Left Location of Control /// private int StartX = 0;
/// /// To persist MouseDown Top Location of Control /// private int StartY = 0;
/// /// TO persist Start Left Location of Control /// private int StartLocX = 0;
/// /// TO persist Start Top Location of Control /// private int StartLocY = 0;
/// /// Active BPMapCanvas /// private IBPMapCanvas BPMapCanvasform = null;
/// /// Tag for MultiSelection Panel /// It can be any value. It is only used for identifying the MultiSelection Panel /// protected const long MultiSelectionPanelTag = 81821603;
/// /// Tag for Copy of MultiSelection panel /// This can be any value. It is used only to identify the Copy of MultiSelectionPanel /// protected const long CopyPanelTag = 82813016;
/// /// To Draw MultiSelection Rectangle on BPMapCanvas /// private Graphics MultiGraphics;
/// /// To persist Selection rectangle Color /// private Color BPMapBackColor;
/// /// Pen for Drawing Selection rectangle /// private Pen pen = new Pen(Color.Black, 1);
/// /// Context Menu Strip for MultiSelection panel /// private ContextMenuStrip cmnuMultiSelection;
/// /// ToolStripMenu Item for Copy of MultiSelection /// private ToolStripMenuItem CopyMultiSelection = new ToolStripMenuItem();
/// /// ToolStripMenu Item for Delete of MultiSelection /// private ToolStripMenuItem DeleteMultiSelection = new ToolStripMenuItem();
/// /// ToolStripMenu Item for Cut operation of MultiSelection /// private ToolStripMenuItem CutMultiSelection = new ToolStripMenuItem();
/// /// ToolStripSeparator for MultiSelection ContextMenuStrip /// private ToolStripSeparator Separator1 = new ToolStripSeparator();
/// /// ToolStripSeparator for MultiSelection ContextMenuStrip /// private ToolStripSeparator Separator2 = new ToolStripSeparator();
/// /// ToolStripMenu Item for DeselectAll operation of MultiSelection /// private ToolStripMenuItem DeselectAll = new ToolStripMenuItem();
/// /// ToolStripSeparator for MultiSelection ContextMenuStrip /// private ToolStripSeparator Separator3 = new ToolStripSeparator();
/// /// Panel for MultiSelection of Elements on BPMapCanvas /// private SelectPanel MultiSelectionPanel;
/// /// To set the Back Color of MultiSelection panel /// private Color MultiSelectBackColor = Color.MintCream;
/// /// Padding for the MultiSelection panel /// private int MultiSelectionPadding = 2;
/// /// For adding resource keys and getting the value from resources /// protected Hashtable HtblResourceKeyValuesInfo = new Hashtable();
/// /// For displaying Message for Cut and Delete operation of MultiSelection /// private string MsgMultiSelectionUndo;
/// /// For displaying Caption of MessageBox for Cut and Delete operation of MultiSelection /// private string CaptionMultiSelectionUndo;
/// /// To persist wether existance of MultiSelection /// it is true if there is MultiSelection /// else it is false. /// public bool IsMultiSelection = false;
/// /// To Hold reference of the Controls that are in MultiSelection /// public ArrayList MultiSelectedElementsList = new ArrayList();
#endregion
#region Constructor
/// /// Default Constructor /// Creates ContextMenuStrip for MultiSelection /// Gettiing Resources /// Instantiating The ResourceManager /// //public MultipleSelectionControl() //{ // try // { // //get the Resources // SetResourceInfo();
// //Create the ConrtextMenuStrip for MultiSelectionPanel // AddContextMenuStrip();
// #region Instantiating The ResourceManager
// //This is for initializing the resource manager and specifying the culture info // try // { // if (BPDResourceManager.ResourceManagerObject == null) // { // BPDResourceManager.RefreshCultureInfo();
// }//End of if
// }//End of try
// //To Catch InvalidCultureNameException // catch (BPDInvalidCultureNameException ICex) // { // MessageBox.Show(ICex.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
// }//End of catch
// //To Catch MissingSatelliteAssemblyException // catch (MissingSatelliteAssemblyException saex) // { // BPDBaseException ObjBPDBaseException = new BPDBaseException(saex.Message, saex); // MessageBox.Show(saex.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
// }//End of catch
// //To Catch BPDBaseException // catch (BPDBaseException exObject) // { // BPDBaseException ObjBPDBaseException = new BPDBaseException(exObject.Message, exObject); // MessageBox.Show(exObject.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
// }//End of catch
// //To Catch Generic Exceptions // catch (Exception ex) // { // BPDBaseException exObj = new BPDBaseException(ex.Message, ex); // MessageBox.Show(exObj.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
// }//End of catch
// #endregion
// }//End of try
// //To Catch BPDBaseExceptions // catch (BPDBaseException ObjBPDBaseException) // { // MessageBox.Show(ObjBPDBaseException.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
// }//End of catch
// //To catch Generic Exceptions // catch (Exception ex) // { // BPDBaseException exobj = new BPDBaseException(ex.Message, ex); // MessageBox.Show(ex.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
// }//End of catch
//}//ENd of public MultipleSelectionControl()
/// /// Constructor that takes the Active BPMapCnavas as argument /// Creates ContextMenuStrip for MultiSelection /// Getting Resources /// Instantiating The ResourceManager /// /// frm represents ActiveBPMapCanvas public MultipleSelectionControl(IBPMapCanvas frm) { try { //get the Resources SetResourceInfo();
BPMapCanvasform = frm; //Create the ConrtextMenuStrip for MultiSelectionPanel AddContextMenuStrip();
#region Instantiating The ResourceManager
//This is for initializing the resource manager and specifying the culture info try { if (BPDResourceManager.ResourceManagerObject == null) { BPDResourceManager.RefreshCultureInfo(); }//End of if
}//End of try
//To catch InvalidCultureNameException catch (BPDInvalidCultureNameException ICex) { MessageBox.Show(ICex.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
//To catch MissingSatelliteAssemblyException catch (MissingSatelliteAssemblyException saex) { BPDBaseException ObjBPDBaseException = new BPDBaseException(saex.Message, saex); MessageBox.Show(saex.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
//To Catch BPDBaseException catch (BPDBaseException exObject) {
MessageBox.Show(exObject.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
//To Catch Generic Exceptions catch (Exception ex) { BPDBaseException exObj = new BPDBaseException(ex.Message, ex); MessageBox.Show(exObj.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
#endregion
}//End of try
//To Catch BPDBaseExceptions catch (BPDBaseException ObjBPDBaseException) { MessageBox.Show(ObjBPDBaseException.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
//To catch Generic Exceptions catch (Exception ex) { BPDBaseException exobj = new BPDBaseException(ex.Message, ex); MessageBox.Show(ex.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
}//End of public MultipleSelectionControl(Form)
/// /// To Instantiate the Resource Manager /// static MultipleSelectionControl() { try { #region Instantiating The ResourceManager
//This is for initializing the resource manager and specifying the culture info try { if (BPDResourceManager.ResourceManagerObject == null) { BPDResourceManager.RefreshCultureInfo();
}//End of if
}//End of try
//To Catch InvalidCultureNameException catch (BPDInvalidCultureNameException ICex) { MessageBox.Show(ICex.Message, BPDResourceManager.GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
//To Catch MissingSatelliteAssemblyException catch (MissingSatelliteAssemblyException saex) { BPDBaseException ObjBPDBaseException = new BPDBaseException(saex.Message, saex); MessageBox.Show(saex.Message, BPDResourceManager.GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
//To Catch BPDBaseException catch (BPDBaseException exObject) {
MessageBox.Show(exObject.Message, BPDResourceManager.GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
//To Catch Generic Exceptions catch (Exception ex) { BPDBaseException exObj = new BPDBaseException(ex.Message, ex); MessageBox.Show(exObj.Message, BPDResourceManager.GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
#endregion
}//End of try
//To Catch BPDBaseExceptions catch (BPDBaseException ObjBPDBaseException) { MessageBox.Show(ObjBPDBaseException.Message, BPDResourceManager.GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
//To catch Generic Exceptions catch (Exception ex) { BPDBaseException exobj = new BPDBaseException(ex.Message, ex); MessageBox.Show(ex.Message, BPDResourceManager.GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch }//End of static MultipleSelectionControl()
#endregion
#region Globalization
/// /// SetResourceInfo method for getting the values from resource repository and assigning the values /// to the particulat control /// private void SetResourceInfo() { try { // Adding all the relevant keys information to the HtblResourceKeyValuesInfo //Resource keys for multiselection element context menu -- need to be added to the ControlVertex class HtblResourceKeyValuesInfo.Add("BPDGraphicalLookAndFeelCanvasEleMulConMnuCopy", null); HtblResourceKeyValuesInfo.Add("BPDGraphicalLookAndFeelCanvasEleMulConMnuDelete", null); HtblResourceKeyValuesInfo.Add("BPDGraphicalLookAndFeelCanvasEleMulConMnuCut", null); HtblResourceKeyValuesInfo.Add("BPDBPMapCanvasMultiSelectionUndoMsg", null); HtblResourceKeyValuesInfo.Add("BPDBPMapCanvasMulSelectionUndoCaption", null); HtblResourceKeyValuesInfo.Add("BPDGraphicalLookAndFeelCanvasEleMulConMnuDeselect", null);
BPDResourceManager.GetResourceKeyValues(ref HtblResourceKeyValuesInfo);
}//End of try
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception ex) { BPDBaseException exObj = new BPDBaseException(ex.Message, ex); MessageBox.Show(exObj.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch }// End of private void SetResourceInfo()
/// /// This method returns the value of the resource Key /// /// Key of the resource /// Value of the Resource as string public string GetResourceValue(string strResourceKey) { try { return BPDResourceManager.GetResourceValue(strResourceKey);
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//To catch Generic Exceptions catch (Exception) { throw;
}//End of catch
}//End of public string GetResourceValue(string)
#endregion
#region Events
#region MouseDown, MouseMove, MouseUp Events of BpMapCanvas
/// /// Getting Starting points for MultipleSelection Rectangle /// DeSelect the Controls on the BPMapCanvas /// Releasing the MultipleSelection if any. /// /// /// public void Form_MouseDown(object sender, MouseEventArgs e) { try { //Active BPMapCanvas BPMapCanvasform = (IBPMapCanvas)sender; BPMapBackColor = ((Form)BPMapCanvasform).BackColor; IsMultiDrag = true;
//Deselect All the Elements on BPMapCanvas BPMapCanvasform.VortexControl.DeSelectAll((Form)BPMapCanvasform);
//Clear the MultiSelected Elements List MultiSelectedElementsList.Clear();
//if there is MultiSelection Then remove the MultiSelection if (IsMultiSelection == true) { //Remove the multiSection Panel ReleaseMultipleSelection((Form)BPMapCanvasform);
}//End of if
if (e.Button == MouseButtons.Left) { //Getting MousePositions only when Left MouseButton Clicks MultiStartX = e.X; MultiStartY = e.Y;
}//End of if
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void Form_MouseDown(object, MouseEventArgs)
/// /// To Draw the MultiSelection rectangle when Mouse Left Button Clicked /// /// /// public void Form_MouseMove(object sender, MouseEventArgs e) { try { if (e.Button == MouseButtons.Left && IsMultiDrag == true) { //To Draw the Selection rectangle on BPMapCanvas only if Left MouseButton Clicked BPMapCanvasform = (IBPMapCanvas)sender; MultiGraphics = ((Form)BPMapCanvasform).CreateGraphics();
//Change the Mouse pointer to cross so that it will represent the Selection ((Form)BPMapCanvasform).Cursor = Cursors.Cross;
//To Get the Location of Selection Rectangle Point RectangleLocation = GetDrawRectangleLocation(e); Rectangle SelectionRec = new Rectangle(RectangleLocation.X, RectangleLocation.Y, diffX, diffY); MultiGraphics.Clear(BPMapBackColor); //Draw the Selection rectangle as Dotted Rectangle pen.DashStyle = DashStyle.Dot; MultiGraphics.DrawRectangle(pen, SelectionRec);
}//End of if
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void Form_MouseMove(object, MouseEventArgs)
/// /// Craete a Panel for Multiple Selection /// Adding Selected Controls to the MultiSelection pnael /// /// /// public void Form_MouseUp(object sender, MouseEventArgs e) { try { //Represents Active BPMapCanvas BPMapCanvasform = (IBPMapCanvas)sender;
//Change the Mouse pointer to Default so that it will represent pointer ((Form)BPMapCanvasform).Cursor = Cursors.Default;
if (e.Button == MouseButtons.Left && IsMultiDrag == true) { //Clearing all graphics drawn earlier MultiGraphics = ((Form)BPMapCanvasform).CreateGraphics(); MultiGraphics.Clear(BPMapBackColor);
//Set the Drag Mode to false to stop the MultiSelection IsMultiDrag = false;
//Create MultipleSelection Panel for holding Multiple selected Elements MultiSelectionPanel = new SelectPanel(); MultiSelectionPanel.Tag = MultiSelectionPanelTag; //Set the Location and size of panel as of the Selection rectangle MultiSelectionPanel.Location = new Point(GetDrawRectangleLocation(e).X, GetDrawRectangleLocation(e).Y); MultiSelectionPanel.Size = new Size(diffX, diffY); MultiSelectionPanel.BackColor = MultiSelectBackColor; MultiSelectionPanel.BorderStyle = BorderStyle.FixedSingle; MultiSelectionPanel.Cursor = Cursors.SizeAll; MultiSelectionPanel.Padding = new Padding(MultiSelectionPadding);
//If MultiSelection Panel Size Exeeds the BPMapCanvas then reduce the width of MultiSelection panel by the amount it is exceeding if ((MultiSelectionPanel.Location.X + MultiSelectionPanel.Width) > ((Form)BPMapCanvasform).Width) { MultiSelectionPanel.Width = MultiSelectionPanel.Width - ((MultiSelectionPanel.Location.X + MultiSelectionPanel.Width) - ((Form)BPMapCanvasform).Width);
}//End of if
//If MultiSelection Panel Size Exeeds the BPMapCanvas then reduce the Height of MultiSelection panel by the amount it is exceeding if ((MultiSelectionPanel.Location.Y + MultiSelectionPanel.Height) > ((Form)BPMapCanvasform).Height) { MultiSelectionPanel.Height = MultiSelectionPanel.Height - ((MultiSelectionPanel.Location.Y + MultiSelectionPanel.Height) - ((Form)BPMapCanvasform).Height);
}//End of if
//Add the controls that are in MultiSelection bounds to MultiSelection panel AddControlsToMultiSelectionPanel(MultiSelectionPanel, (Form)BPMapCanvasform);
//Add the MultiSelection Panel to the BPMapCanvas //only when atleast one Control is selected. if (MultiSelectionPanel.Controls.Count == 0) { return;
}//End of if
//Add the MultiSelection Panel to the BPMapCanvas ((Form)BPMapCanvasform).Controls.Add(MultiSelectionPanel); MultiSelectionPanel.SendToBack(); //Set the Selected Control as the MultiSelection Panel BPMapCanvasform.VortexControl.SelectedControl = MultiSelectionPanel;
//set the MultiSelection flag status to true IsMultiSelection = true;
//Assign Events to the MultiSelection Panel AssignEventsToMultiSelectionPanel(MultiSelectionPanel);
//Add the ContextMenuStrip to the MultiSelection Panel MultiSelectionPanel.ContextMenuStrip = cmnuMultiSelection; MultiSelectionPanel.SendToBack();
//if the MultiSelection Panel left position is less than Zero i.e lessthan ActiveBPMapCanvas Left position //Then Make the left position of MultiSelecion Panel to Zero. if (MultiSelectionPanel.Left < 0) { MultiSelectionPanel.Left = 0; }//End of if
//if the MultiSelection Panel Top position is less than Zero i.e lessthan ActiveBPMapCanvas Left position //Then Make the Top position of MultiSelecion Panel to Zero. if (MultiSelectionPanel.Top < 0) { MultiSelectionPanel.Top = 0; }//End of if
//Refresh the Element Combobox of Property grid BPMapCanvasform.ObjUIScreen.GetPropertyWindow().RefreshElementCombobox();
//persist the Location of MultiSelecion Panel //Later to check for the changes to save. StartLocX = MultiSelectionPanel.Left; StartLocY = MultiSelectionPanel.Top;
}//End of if
//Make the Variables to Zero MultiStartX = 0; MultiStartY = 0;
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void Form_MouseUp(object, MouseEventArgs)
#endregion
#region MouseDown, MouseMove, MouseUp Events of MultiSelection panel
/// /// To Get the Initial Location of the MultiSelection Panel. /// To Create the Copy of the MultiSelection panel /// /// /// private void MultiSelectionPanel_MouseDown(object sender, MouseEventArgs e) { try { if (e.Button == MouseButtons.Left) { //Get the MouseDown location of MultiSelection Panel to move According this StartX = e.X; StartY = e.Y;
//Get the Location of the MultiSelection panel //To place it back to original position if Overlapping occurs StartLocX = ((Control)sender).Location.X; StartLocY = ((Control)sender).Location.Y; ((Control)sender).SendToBack();
//Creating copy of the MultiSelection panel to show the initial position of MultiSelectionPanel //CreateCopyOfMultiSelection((Control)sender); }//End of if
}//End of try
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception ex) { BPDBaseException exObj = new BPDBaseException(ex.Message, ex); MessageBox.Show(exObj.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
}//End of private void MultiSelectionPanel_MouseDown(object, MouseEventArgs)
/// /// To Move the MultiSelection panel with MouseMovement /// only when Left button is clicked /// /// /// private void MultiSelectionPanel_MouseMove(object sender, MouseEventArgs e) { try { //If Left Mouse Button Clicked then move the MultiSelection Panel if (e.Button == MouseButtons.Left && System.Windows.Forms.Control.ModifierKeys != Keys.Control) { //If the Mouse Left Button is clicked then Move the Element Control ControlSelected = (Control)sender;
int l = ControlSelected.Left + e.X - StartX; int t = ControlSelected.Top + e.Y - StartY;
//To Check wehther the control is moved out of Left and Top positions of the BPMapCanvas l = (l < 0) ? 0 : l; t = (t < 0) ? 0 : t;
ControlSelected.Left = l; ControlSelected.Top = t;
//Send the MultiSelection control to back so that Element Overlapping can be visible. ControlSelected.SendToBack();
//Checking the Overlapping of InnerControls of MultiSelection Panel With other Controls on BPMapCanvas foreach (Control IneerControl in ControlSelected.Controls) { if (IsMultiSelectionOverlapped(IneerControl) == true) { //If Overlapped Make the Cursor to No. ControlSelected.Cursor = Cursors.No; return;
}//End of if
//To Change the Cursor to No when Control is moved Out of Left and Top Margin of the BPMapCanvas else if (e.X < 0 || e.Y < 0) { ControlSelected.Cursor = Cursors.No;
}//End of else if
//To change the cursor to SizeAll when Control is moved with in the BPMapCanvas else { //If not Overlapped and the control is with in BPMapCanvas bounds //Make the Cursor to SizeAll ControlSelected.Cursor = Cursors.SizeAll;
}//End of else
}//End of foreach
}//End of if
}//End of try
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception ex) { BPDBaseException exObj = new BPDBaseException(ex.Message, ex); MessageBox.Show(exObj.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
}//End of private void MultiSelectionPanel_MouseMove(object, MouseEventArgs)
/// /// To Dispose the Copy of MultiSelection panel. /// Stop the Movement of MultiSelection panel /// /// /// private void MultiSelectionPanel_MouseUp(object sender, MouseEventArgs e) { try { //Checking the Overlapping of Image in InnerControls of MultiSelection Panel //With the Images in other Controls on BPMapCanvas foreach (Control InnerControl in ((Control)sender).Controls) { if (IsMultiSelectionOverlapped(InnerControl) == true) { //If it is Overlapped MultiSelection Panel is Placed at its Original position ((Control)sender).Left = StartLocX; ((Control)sender).Top = StartLocY; ((Control)sender).Cursor = Cursors.SizeAll;
}//End of if
}//End of foreach
Control ControlSelected = (Control)sender; //Check wether the location of MultiSelection changes or not. If the Location changed then //Enable the Save Menu Items and Icons if (ControlSelected.Left != StartLocX || ControlSelected.Top != StartLocY) { BPMapCanvasform.IsBPMapCanvasSaveRequired = true;
}//End of if
//Set the StartLocation of MultiSelection to change the Save status if it is further moves StartLocX = ControlSelected.Left; StartLocY = ControlSelected.Top;
//Dispose the Copy of the MultiSelection Panel by checking its Tag property and Type foreach (Control ctl in ((Form)BPMapCanvasform).Controls) { if (ctl.GetType().FullName == "System.Windows.Forms.Panel" && (long)ctl.Tag == CopyPanelTag && ctl.Tag != null) { ctl.Dispose();
}//End of if
}//End of foreach
}//End of try
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception ex) { BPDBaseException exObj = new BPDBaseException(ex.Message, ex); MessageBox.Show(exObj.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
}//End of private void MultiSelectionPanel_MouseUp(object, MouseEventArgs)
#endregion
#region MouseDown, MouseMove, MouseUp Events of InnerControls of Multiselection Panel
/// /// Assigning MultiSelection Panel MouseDown Event to the InnerControls of it. /// /// /// private void InnerControl_MouseDown(object sender, MouseEventArgs e) { try { //If the Control Key Holded and Left Mouse Button clicked //Then remove the Element from MultiSelected Elements list and again create the MultiSelection if (e.Button == MouseButtons.Left && System.Windows.Forms.Control.ModifierKeys == Keys.Control) { //Remove the control from List MultiSelectedElementsList.Remove(sender); //Deselect the Control BPMapCanvasform.VortexControl.DeSelectControl((Control)sender);
//Bring the Control to front ((Control)sender).BringToFront();
//Again create the MultiSelection with remaining MultiSelected Elements CreateMultiSelection();
}//End of if else { //Assigning InnerControl MouseDown Event to the MultiSelection Panel MouseDownEvent MultiSelectionPanel_MouseDown((object)((Control)sender).Parent, e);
}//End of else
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of private void InnerControl_MouseDown(object, MouseEventArgs)
/// /// Assigning MouseMove Event of the MultiSelection Panel to the InnerControls of it. /// /// /// private void InnerControl_MouseMove(object sender, MouseEventArgs e) { try { //Assigning InnerControl MouseMove Event to the MultiSelection Panel MouseMove Event MultiSelectionPanel_MouseMove((object)((Control)sender).Parent, e); }//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of private void InnerControl_MouseMove(object, MouseEventArgs)
/// /// Assigning MouseUp Event of the MultiSelection Panel to the InnerControls of it. /// /// /// private void InnerControl_MouseUp(object sender, MouseEventArgs e) { try { //Assigning InnerControl MouseUp Event to the MultiSelection Panel MouseUp Event MultiSelectionPanel_MouseUp((object)((Control)sender).Parent, e);
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of private void InnerControl_MouseUp(object, MouseEventArgs)
#endregion
#region ContextMenu Events
/// /// To Copy the Multiselection panel to the BPClipBoard /// /// /// private void CopyMultiSelection_Click(object sender, EventArgs e) { try { CopyMultiSelectionPanel();
}//End of try
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception ex) { BPDBaseException exObj = new BPDBaseException(ex.Message, ex); MessageBox.Show(exObj.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
}//End of private void CopyMultiSelection_Click(object, EventArgs)
/// /// To Copy the MultiSelection Panel to ClipBoard and /// To Remove the MultiSelection Panel from BPMapCanvas /// /// /// private void CutMultiSelection_Click(object sender, EventArgs e) { try { //Showing Confermation Message while Cut operation performed on MultiSelection CaptionMultiSelectionUndo = HtblResourceKeyValuesInfo["BPDBPMapCanvasMulSelectionUndoCaption"].ToString(); MsgMultiSelectionUndo = HtblResourceKeyValuesInfo["BPDBPMapCanvasMultiSelectionUndoMsg"].ToString(); DialogResult Result = MessageBox.Show(MsgMultiSelectionUndo, CaptionMultiSelectionUndo, MessageBoxButtons.YesNo, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
if (Result == DialogResult.Yes) { //Copying the MultiSelection Panel to the BPClipBoard. CopyMultiSelectionPanel();
//Delete the Controls in the MultiSelection Panel from BPMapCanvas and its reference from Propertywindow DleteMultiSelectionControls(((Form)BPMapCanvasform)); //As Changes are Done Enable the Save Menu Items BPMapCanvasform.IsBPMapCanvasSaveRequired = true;
}//End of if
}//End of try
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception ex) { BPDBaseException exObj = new BPDBaseException(ex.Message, ex); MessageBox.Show(exObj.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
}//End of private void CutMultiSelection_Click(object, EventArgs)
/// /// To Remove the MultiSelected Controls along with MultiSelection Panel /// /// /// private void DeleteMultiSelection_Click(object sender, EventArgs e) { try { //Showing Confermation Message while Delete operation performed on MultiSelection CaptionMultiSelectionUndo = HtblResourceKeyValuesInfo["BPDBPMapCanvasMulSelectionUndoCaption"].ToString(); MsgMultiSelectionUndo = HtblResourceKeyValuesInfo["BPDBPMapCanvasMultiSelectionUndoMsg"].ToString(); DialogResult Result = MessageBox.Show(MsgMultiSelectionUndo, CaptionMultiSelectionUndo, MessageBoxButtons.YesNo, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
if (Result == DialogResult.Yes) { //Delete the Controls in the MultiSelection Panel from BPMapCanvas and its reference from Propertywindow DleteMultiSelectionControls(((Form)BPMapCanvasform));
//As Changes are Done Enable the Save Menu Items BPMapCanvasform.IsBPMapCanvasSaveRequired = true; }//End of if
}//End of try
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception ex) { BPDBaseException exObj = new BPDBaseException(ex.Message, ex); MessageBox.Show(exObj.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
} //End of private void DeleteMultiSelection_Click(object, EventArgs)
/// /// To Deselect the MultiSelection. /// /// /// private void DeselectAll_Click(object sender, EventArgs e) { try { //Clear the Multi Selected Elements List MultiSelectedElementsList.Clear(); //Release the Multi Selection of Elements ReleaseMultipleSelection((Form)BPMapCanvasform); //Show canvas properties BPMapCanvasform.ObjUIScreen.GetPropertyWindow().RefreshElementCombobox();
}//End of try
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception ex) { BPDBaseException exObj = new BPDBaseException(ex.Message, ex); MessageBox.Show(exObj.Message, GetResourceValue("BPDBaseExceptionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}//End of catch
}//End of private void DeselectAll_Click(object , EventArgs)
#endregion
#endregion
#region Methods
/// /// Adding Controls that are with in Selection rectangle to the MultiSelection panel /// /// /// frm represents Active BPMapCanvas private void AddControlsToMultiSelectionPanel(Panel SelectionPanel, Form frm) { try { //To persist the Save requirement of BPMapCanvas //Because after the following code executed the Save Requirement changes to true //as the selected elements location changes bool IsSaveRequired = false; IsSaveRequired = BPMapCanvasform.IsBPMapCanvasSaveRequired;
//Checking every control on the BPMapCanvs for (int Iteration = 0; Iteration < frm.Controls.Count; Iteration++) { Control ControlSelected = frm.Controls[Iteration]; //Checking for IBPElements if (ControlSelected is IBPElement) { //Is the Control with in the MultiSelection panel Bounds if (IsControlWithinTheSelectionRange(SelectionPanel, ControlSelected) == true) { //----------------------------------------------------------------------------------------------- //This code is added by Siva.Vissamsetti on 15-Dec -2006 to fix the BUG NO:111 //Add the Selected Elements to the Selected Elements array List //CntrlVertex.DeSelectControl(ControlSelected); ((IBPElement)ControlSelected).IsSelected = false; MultiSelectedElementsList.Add(ControlSelected);
}//End of if
}//End of if }//End of for
//Check the Location and size of Selection panel with respect to the Selected controls //If necessary chage the Location and size of Selection Panel according to requirement for (int Iteration = 0; Iteration < MultiSelectedElementsList.Count; Iteration++) { Control ControlSelected = (Control)MultiSelectedElementsList[Iteration];
// If MultiSelection Panel Left Location is less than the Control Location //Then Make the MultiSelection Panel location as the Control Location //And increase the Width if (SelectionPanel.Left > ControlSelected.Left) { int IncreasedWidth = SelectionPanel.Left + MultiSelectionPadding - ControlSelected.Left; SelectionPanel.Width = SelectionPanel.Width + IncreasedWidth; SelectionPanel.Left = ControlSelected.Left - MultiSelectionPadding;
}//End of if
//f MultiSelection Panel Top Location is less than the Control Location //Then Make the MultiSelection Panel location as the Control Location //And increase the Height if (SelectionPanel.Top > ControlSelected.Top) { int IncreasedHeight = SelectionPanel.Top + MultiSelectionPadding - ControlSelected.Top; SelectionPanel.Height = SelectionPanel.Height + IncreasedHeight; SelectionPanel.Top = ControlSelected.Top - MultiSelectionPadding;
}//End of if
//If SelectionPanel Bottom Left Position is Less than the SelectedControl BottomLeft Position //Then Incrase the Width of the Selection Panel Upto the Selected Control BottomLeft Corner if ((SelectionPanel.Left + SelectionPanel.Width) < (ControlSelected.Left + ControlSelected.Width)) { int IncreasedWidth = (ControlSelected.Left + ControlSelected.Width) - (SelectionPanel.Left + SelectionPanel.Width); SelectionPanel.Width = SelectionPanel.Width + IncreasedWidth;
}//End of if
//If SelectionPanel Bottom Position is Less than the SelectedControl Bottom Position //Then Incrase the Height of the Selection Panel Upto the Selected Control Bottom if ((SelectionPanel.Top + SelectionPanel.Height) < (ControlSelected.Top + ControlSelected.Height)) { int IncreasedHeight = (ControlSelected.Top + ControlSelected.Height) - (SelectionPanel.Top + SelectionPanel.Height); SelectionPanel.Height = SelectionPanel.Height + IncreasedHeight;
}//End of if
}//End of for
//------------------------------------------------------------------------------------------------------------------
//Add the Elements which are in Selected Elements Array List to the MultiSelection panel for (int Iteration = 0; Iteration < MultiSelectedElementsList.Count; Iteration++) { Control ControlSelected = (Control)MultiSelectedElementsList[Iteration];
//Make the control invisible to avoid blur. ControlSelected.Visible = false;
//Select the control with White VertexPoints BPMapCanvasform.VortexControl.SelectControl(ControlSelected);
// Need to remove the OriginalEvents of Controls Added to MultiSelection Panel. BPMapCanvasform.RemoveBpMapElementEvents(ControlSelected);
//Add the MultiSelection ContextMenuStrip to InnerControls of MultiSelectionPanel. ControlSelected.ContextMenuStrip = cmnuMultiSelection;
//Assigning new events to the InnerControls of MultiSelection panel AssignEventsToInnerControls(ControlSelected);
//Add controls to the MultiSelection panel SelectionPanel.Controls.Add(ControlSelected);
//Calculations for Locatiuon and size of IneerControls of MultiSelectionPanel ControlSelected.Location = new Point(ControlSelected.Location.X - SelectionPanel.Location.X, ControlSelected.Location.Y - SelectionPanel.Location.Y); ControlSelected.Cursor = Cursors.SizeAll;
//Make the Control Visible to true which ia made false later ControlSelected.Visible = true;
}//End of for
//with above Operation the Save Requirement of BPMapCanvas Changes //Now assign the previous state which is stored in Another flag before this operation BPMapCanvasform.IsBPMapCanvasSaveRequired = IsSaveRequired; }//End of try catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of private void AddControlsToMultiSelectionPanel(Panel, Form)
/// /// Checking the Control Location withrespect to MultiSelection panel bounds /// If the control is with in the bounds it will return true else false /// /// /// /// private bool IsControlWithinTheSelectionRange(Panel SelectionPanel, Control CanvasControl) { try { //Persisting bounds of SelectionPanel for checking int PnlLocX = SelectionPanel.Location.X; int PnlLocY = SelectionPanel.Location.Y; int PnlWidth = SelectionPanel.Width; int PnlHeight = SelectionPanel.Height;
//Persisiting the bounds of Control on BPMapCanvas for checking int CtlLocX = CanvasControl.Location.X; int CtlLocY = CanvasControl.Location.Y; int CtlWidth = CanvasControl.Width; int CtlHeight = CanvasControl.Height; //Checking for Right Upside Corner selection if ((PnlLocX <= CtlLocX && CtlLocX <= (PnlWidth + PnlLocX)) && (PnlLocY <= CtlLocY && CtlLocY <= (PnlHeight + PnlLocY))) { return true;
}//End of if
//Checking for Left Upside Corner if ((PnlLocX <= (CtlLocX + CtlWidth) && (CtlLocX + CtlWidth) <= (PnlLocX + PnlWidth)) && (PnlLocY <= CtlLocY && CtlLocY <= (PnlLocY + PnlHeight))) { return true;
}//End of if
//Checking for Right bottom side corner if ((PnlLocX <= CtlLocX && CtlLocX <= (PnlLocX + PnlWidth)) && (PnlLocY <= (CtlLocY + CtlHeight) && (CtlLocY + CtlHeight) <= (PnlLocY + PnlHeight))) { return true;
}//End of if
//Checking for Left bottom side corner if ((PnlLocX <= (CtlLocX + CtlWidth) && (CtlLocX + CtlWidth) <= (PnlLocX + PnlWidth)) && (PnlLocY <= (CtlLocY + CtlHeight) && (CtlLocY + CtlHeight) <= (PnlLocY + PnlHeight))) { return true;
}//End of if
//Checking for selection of control from left side without touching corners if ((PnlLocX <= CtlLocX) && ((PnlLocX + PnlWidth) >= CtlLocX) && ((CtlLocY <= PnlLocY) && (((PnlLocY + PnlHeight) >= CtlLocY) && ((PnlLocY + PnlHeight) <= (CtlLocY + CtlHeight))))) { return true;
}//End of if
//Checking for Selection of control form right side without touching corners if ((PnlLocX >= CtlLocX) && (PnlLocX <= (CtlLocX + CtlWidth)) && ((CtlLocY <= PnlLocY) && (((PnlLocY + PnlHeight) >= CtlLocY) && ((PnlLocY + PnlHeight) <= (CtlLocY + CtlHeight))))) { return true;
}//End of if
//Checking for Selection of control from Top side of control without touching corners if (((PnlLocX >= CtlLocX) && ((PnlLocX + PnlWidth) <= (CtlLocX + CtlWidth))) && ((CtlLocY >= PnlLocY) && ((PnlLocY + PnlHeight) >= CtlLocY))) { return true;
}//End of if
//Checking for selection of control from bottom side without touching the corners if (((PnlLocX >= CtlLocX) && ((PnlLocX + PnlWidth) <= (CtlLocX + CtlWidth))) && (((CtlLocY + CtlHeight) >= PnlLocY) && ((PnlLocY + PnlHeight) >= (CtlLocY + CtlHeight)))) { return true;
}//End of if
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
//The Control is Not Overlapping with other Controls return false;
}// End of private bool IsControlWithinTheSelectionRange(Panel, Control)
/// /// Getting the Location of the Selection rectangle /// to draw the selection rectangle on BPMapCanvas /// considering the laft, right, top, bottom movement of mouse point /// /// /// private Point GetDrawRectangleLocation(MouseEventArgs e) {
//To Draw a rectangle when the MouseMove Event occur on BPMapCanvas int RectangleX = MultiStartX; int RectangleY = MultiStartY;
try { //To persist the width and height of selection rectangle. diffX = 0; diffY = 0;
// Calculating diffX if (e.X > MultiStartX) { diffX = e.X - MultiStartX;
} //End of if
else if (MultiStartX > e.X) { diffX = MultiStartX - e.X; RectangleX = e.X;
} //End of else if else { diffX = 0;
} //End of else
// Calculating diffY if (e.Y > MultiStartY) { diffY = e.Y - MultiStartY;
} //End of if
else if (MultiStartY > e.Y) { diffY = MultiStartY - e.Y; RectangleY = e.Y;
} //End of else if else { diffY = 0;
} //End of else
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
return new Point(RectangleX, RectangleY);
} // End of public Point GetDrawRectangleLocation(MouseEventArgs)
/// /// Assigning Events to the MultiSelection Panel for Moving /// /// public void AssignEventsToMultiSelectionPanel(Panel MultiSelectionPanel) { //Assign MouseDown, MouseMove and MouseUp events that are required for moving MultiSelection Controls MultiSelectionPanel.MouseDown += new MouseEventHandler(MultiSelectionPanel_MouseDown); MultiSelectionPanel.MouseMove += new MouseEventHandler(MultiSelectionPanel_MouseMove); MultiSelectionPanel.MouseUp += new MouseEventHandler(MultiSelectionPanel_MouseUp);
} //End of private void AssignEventsToMultiSelectionPanel(Panel)
/// /// Currently this method is not in Use. /// Getting Vertexpoints to the MultiSelection panel /// So that it is visible like a selected control /// /// private void SelectMultiSelectionPanel(Panel MultiSelectionpanel) { try { //Graphics to darw vertexRectangles and border Graphics g = Graphics.FromHwnd(MultiSelectionpanel.Handle);
//Drawing Border Across MultiSelection Panel ControlPaint.DrawBorder(g, new Rectangle(0, 0, MultiSelectionpanel.Width, MultiSelectionpanel.Height), Color.Black, ButtonBorderStyle.Dotted);
//Corener rectangles of MUltiselection Panel VertexPoints Rectangle rec1 = new Rectangle(0, 0, MultiVertexSize, MultiVertexSize); Rectangle rec2 = new Rectangle(MultiSelectionpanel.Width - MultiVertexSize, 0, MultiVertexSize, MultiVertexSize); Rectangle rec3 = new Rectangle(0, MultiSelectionpanel.Height - MultiVertexSize, MultiVertexSize, MultiVertexSize); Rectangle rec4 = new Rectangle(MultiSelectionpanel.Width - MultiVertexSize, MultiSelectionpanel.Height - MultiVertexSize, MultiVertexSize, MultiVertexSize);
//Middle Rectangles of MultiSelectionPanel VertexPoints Rectangle rec5 = new Rectangle((MultiSelectionpanel.Width / 2) - (MultiVertexSize / 2), 0, MultiVertexSize, MultiVertexSize); Rectangle rec6 = new Rectangle(0, ((MultiSelectionpanel.Height / 2) - (MultiVertexSize / 2)), MultiVertexSize, MultiVertexSize); Rectangle rec7 = new Rectangle((MultiSelectionpanel.Width - MultiVertexSize), ((MultiSelectionpanel.Height / 2) - (MultiVertexSize / 2)), MultiVertexSize, MultiVertexSize); Rectangle rec8 = new Rectangle((MultiSelectionpanel.Width / 2) - (MultiVertexSize / 2), MultiSelectionpanel.Height - MultiVertexSize, MultiVertexSize, MultiVertexSize);
//Drawing the Rectangles across the MultiSelection panel ControlPaint.DrawBorder(g, rec1, Color.Black, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, rec2, Color.Black, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, rec3, Color.Black, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, rec4, Color.Black, ButtonBorderStyle.Solid);
ControlPaint.DrawBorder(g, rec5, Color.Black, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, rec6, Color.Black, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, rec7, Color.Black, ButtonBorderStyle.Solid); ControlPaint.DrawBorder(g, rec8, Color.Black, ButtonBorderStyle.Solid);
//Fill the VertexRectangles with Black Color. Brush b = new SolidBrush(Color.Black); g.FillRectangle(b, rec1); g.FillRectangle(b, rec2); g.FillRectangle(b, rec3); g.FillRectangle(b, rec4); g.FillRectangle(b, rec5); g.FillRectangle(b, rec6); g.FillRectangle(b, rec7); g.FillRectangle(b, rec8);
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of private void SelectMultiSelectionPanel(Panel)
/// /// Assigning MultiSelection Panel Events to the Controls that are added to it. /// so that even with the innercontrol movement the multiselection panel moves /// /// private void AssignEventsToInnerControls(Control InnerControl) { //Assign MouseDown,MouseMove,MouseUp events for Innercontrols of MultiSelection Panel InnerControl.MouseDown += new MouseEventHandler(InnerControl_MouseDown); InnerControl.MouseMove += new MouseEventHandler(InnerControl_MouseMove); InnerControl.MouseUp += new MouseEventHandler(InnerControl_MouseUp);
} //End of private void AssignEventsToInnerControls(Control)
/// /// Creating Copy of MultiSelection when MouseDown Occurs on MultiSelectionPanel /// /// private void CreateCopyOfMultiSelection(Control sender) { try { //Creating copy of the MultiSelection panel //Assign the Properties of MultiSelection panel to Copy Panel Panel CopyPanel = new Panel(); CopyPanel.Location = sender.Location; CopyPanel.Size = sender.Size; CopyPanel.BackColor = sender.BackColor; CopyPanel.BorderStyle = BorderStyle.FixedSingle; CopyPanel.Tag = CopyPanelTag;
//Creating Copy of the InnerControls of the MultiSelection panel foreach (Control InnerControl in sender.Controls) { Control ctl = (Control)Activator.CreateInstance(InnerControl.GetType()); ctl.Location = new Point(InnerControl.Location.X, InnerControl.Location.Y); ctl.Size = new Size(InnerControl.Width, InnerControl.Height); ctl.BackColor = InnerControl.BackColor; ctl.Text = InnerControl.Text; ctl.BringToFront(); BPMapCanvasform.VortexControl.SelectControl(ctl);
//Adding Copy of the InnerControls to the Copy panel CopyPanel.Controls.Add(ctl);
} //End of foreach
//Adding Copy panel to the ActiveBPMapCanvas ((Form)BPMapCanvasform).Controls.Add(CopyPanel);
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of private void CreateCopyOfMultiSelection(Control)
/// /// Removing the MultiSelection Panel by Adding it's InnerControls Back to the BPMapCanvas /// /// public void ReleaseMultipleSelection(Form frm) { try { //To persist the Save requirement of BPMapCanvas //Because after the following code executed the Save Requirement changes to true //as the selected elements location changes bool IsSaveRequired = false; IsSaveRequired = BPMapCanvasform.IsBPMapCanvasSaveRequired;
//Check for MultiSelectionpanel with Tag property foreach (Control CanvasControl in frm.Controls) { //Checking for MultiSelection Panel on the BPMapCanvas if (CanvasControl.Tag != null && (long)CanvasControl.Tag == MultiSelectionPanelTag) { //Removing Controls from MultiSelectionPanel and //Adding them back to BPMapCanvas while (CanvasControl.Controls.Count > 0) { Control MultiSelectionControl = CanvasControl.Controls[0];
//Make the visible false to avoid blur MultiSelectionControl.Visible = false; Control InnerControl = MultiSelectionControl; //Add the original contextmenustrip to Innercontrols InnerControl.ContextMenuStrip = BPMapCanvasform.ContextMenuForClipboard;
BPMapCanvasform.VortexControl.DeSelectControl(InnerControl); //Add the Controls Back to the BPMApCanvas frm.Controls.Add(InnerControl); InnerControl.BringToFront();
//calculations for Innercontrol location InnerControl.Location = new Point(MultiSelectionControl.Location.X + CanvasControl.Location.X, MultiSelectionControl.Location.Y + CanvasControl.Location.Y); InnerControl.Cursor = Cursors.Default;
//TO Remove the MultiSelection Events of Controls RemoveEventsToInnerControls(InnerControl);
//Add original Events to the Controls BPMapCanvasform.AssignEventsToBPElements(InnerControl);
//Make the visible true which is set to false before. MultiSelectionControl.Visible = true;
}//End of while
//Remove the MultiSelection panel from BPMapCanvas frm.Controls.Remove(CanvasControl); CanvasControl.Dispose(); //Set the MultiSelection flag to false IsMultiSelection = false;
//If the location of Multiselection changed then enable the save if (CanvasControl.Left != StartLocX || CanvasControl.Top != StartLocY) { BPMapCanvasform.IsBPMapCanvasSaveRequired = true;
}//End of if
//if the location of multiselection not changed then //there check the Previous status of Save requirement else { //If there is no change in MultiSelection Location then Make the //Save Requirement status to previous one. BPMapCanvasform.IsBPMapCanvasSaveRequired = IsSaveRequired;
}//end of else
}//End of if
}//End of foreach
//Make the Variables to zero after Deselecting MultiSelection //Because if user go for SelectAll and then Deselect it will Starts From Zero Location //If there is no change in MultiSelection Location the Save requirement Should as before //For that we are checking the StartLocation of MultiSelection StartLocX = 0; StartLocY = 0;
}//End of try catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
} //End of private void ReleaseMultipleSelection(Form)
/// /// Remove MultiSelectionPanel Events of the InnerControls when they are removed from MultiSelection panel. /// /// private void RemoveEventsToInnerControls(Control InnerControl) { //Remove MouseDown,MouseMove,MpuseUp events of the InnerControl whel they are removing from multiselection panel InnerControl.MouseDown -= new MouseEventHandler(InnerControl_MouseDown); InnerControl.MouseMove -= new MouseEventHandler(InnerControl_MouseMove); InnerControl.MouseUp -= new MouseEventHandler(InnerControl_MouseUp);
} //End of private void RemoveEventsToInnerControls(Control)
/// /// Check the overlapping of Images of Ineercontrols in Multiselectionpanel with the images of controls on BPMapCanvas /// If the control overlaps then it will return true else false /// /// /// public bool IsMultiSelectionOverlapped(Control ControlSelected) { try { //To Persist the Bounds of Control on MultiSelectionPanel int CtlLocX = ControlSelected.Location.X + ControlSelected.Parent.Location.X; int CtlLocY = ControlSelected.Location.Y + ControlSelected.Parent.Location.Y; int CtlWidth = ControlSelected.Width; int CtlHeight = ControlSelected.Height; //Checking for MultiSelection panel innercontrol overlapping with other controls on BPMapCanvas foreach (Control CanvasControl in ((Form)BPMapCanvasform).Controls) { //If the Checked Control on BPMapCanvas is IBPElement then check if (CanvasControl is IBPElement) { //To persist the Bounds of Element on BPMapCanvas int ElementLocX = CanvasControl.Location.X; int ElementLocY = CanvasControl.Location.Y; int ElementWidth = CanvasControl.Width; int ElementHeight = CanvasControl.Height;
if (CanvasControl != ControlSelected && CanvasControl.Tag == null) { //Checking for Right upper Corner OverLap of Moving Element if ((ElementLocX <= CtlLocX && CtlLocX <= (ElementWidth + ElementLocX)) && (ElementLocY <= CtlLocY && CtlLocY <= (ElementHeight + ElementLocY))) { return true;
} //End of if
//Chacking for Left upperCorner Overlap of Moving Element if ((ElementLocX <= (CtlLocX + CtlWidth) && (CtlLocX + CtlWidth) <= (ElementLocX + ElementWidth)) && (ElementLocY <= CtlLocY && CtlLocY <= (ElementLocY + ElementHeight))) { return true;
} //End of if
//Chacking for Right BottomCorner Overlap of Moving Element if ((ElementLocX <= CtlLocX && CtlLocX <= (ElementLocX + ElementWidth)) && (ElementLocY <= (CtlLocY + CtlHeight) && (CtlLocY + CtlHeight) <= (ElementLocY + ElementHeight))) { return true;
} //End of if
//Chacking for Left BottomCorner Overlap of Moving Element if ((ElementLocX <= (CtlLocX + CtlWidth) && (CtlLocX + CtlWidth) <= (ElementLocX + ElementWidth)) && (ElementLocY <= (CtlLocY + CtlHeight) && (CtlLocY + CtlHeight) <= (ElementLocY + ElementHeight))) { return true;
} //End of if
//If the Moving Control width is Greater that the Element on BPMapCanvas then Check for Full OverLap if (CtlWidth > ElementWidth) { if ((CtlLocX <= ElementLocX) && (ElementLocX <= (CtlLocX + CtlWidth)) && (((CtlLocY <= ElementLocY) && (ElementLocY <= (CtlLocY + CtlHeight))) || ((CtlLocY <= (ElementLocY + ElementHeight)) && ((ElementLocY + ElementHeight) <= (CtlLocY + CtlHeight))))) { return true;
} //End of if
}//End of if
}//End of if
}//End of if
}//End of foreach
}//End of try. catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
return false;
} //End of private bool IsMultiSelectionOverlapped(Control)
/// /// To Delete the MultiSelectionPanel from the BPMapCanvas /// /// public void DleteMultiSelectionControls(Form form) { try { //Check the Existance of MultiSelection //If there is no MultiSelection return.
if (IsMultiSelection == false) return; //Check all the Controls on BPMapCanvas for MultiSelectionpanel foreach (Control ctl in ((Form)BPMapCanvasform).Controls) { //Check for MultiSelection Panel using Tag property and FullName property if (ctl.GetType().FullName == "Exensys.BPD.Common.SelectPanel" && ctl.Tag != null && (long)ctl.Tag == MultiSelectionPanelTag) { //Remove all the Innercontrol references from Array list and BPMapCanvas foreach (Control ctrl in ctl.Controls) { ((Form)BPMapCanvasform).Controls.Remove(ctrl); BPMapCanvasform.BPMapCanvasElementsList.Remove(ctrl);
}//End of foreach
//Removing the MultiSelectionPanel from BPMapCanvas ((Form)BPMapCanvasform).Controls.Remove(ctl); //------------------------------------------------------------- //This code is added by Siva.Vissamsetti to fix the BUG NO:107 //Change the flag to false as MultiSelection is not there IsMultiSelection = false; //------------------------------------------------------------- //Need to Disable the Copy, Cut menu items of UIScreen ToolBar BPMapCanvasform.VortexControl.SelectedControl = null;
//Refreshing the Property Window BPMapCanvasform.ObjUIScreen.GetPropertyWindow().RefreshElementCombobox();
//Enable the Save Menu Items as Chages done to BPMapCanvas BPMapCanvasform.IsBPMapCanvasSaveRequired = true;
}//End of if
}//End of foreach
}//End of try catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void DleteMultiSelectionControls(Form)
/// /// Create the ContextMenustrip for MultiSelection panel and its innercontrols /// private void AddContextMenuStrip() { try { //Creating context menu for the MultiSelection Panel cmnuMultiSelection = new ContextMenuStrip();
//Adding images to ToolStripItems CopyMultiSelection.Image = global::Exensys.BPD.Common.Properties.Resources.copy_l; DeleteMultiSelection.Image = global::Exensys.BPD.Common.Properties.Resources.Active_Delete; CutMultiSelection.Image = global::Exensys.BPD.Common.Properties.Resources.cutsd;
//Add the TooolStripItems to ContextMenuStrip cmnuMultiSelection.Items.AddRange(new ToolStripItem[] { CutMultiSelection, Separator1,CopyMultiSelection,Separator2, DeleteMultiSelection,Separator3,DeselectAll});
//Get the ToolStripItems Text Property from Resources CopyMultiSelection.Text = HtblResourceKeyValuesInfo["BPDGraphicalLookAndFeelCanvasEleMulConMnuCopy"].ToString(); CutMultiSelection.Text = HtblResourceKeyValuesInfo["BPDGraphicalLookAndFeelCanvasEleMulConMnuCut"].ToString(); DeleteMultiSelection.Text = HtblResourceKeyValuesInfo["BPDGraphicalLookAndFeelCanvasEleMulConMnuDelete"].ToString(); DeselectAll.Text = HtblResourceKeyValuesInfo["BPDGraphicalLookAndFeelCanvasEleMulConMnuDeselect"].ToString(); //Assign Click events to ToolStripItems CopyMultiSelection.Click += new EventHandler(CopyMultiSelection_Click); CutMultiSelection.Click += new EventHandler(CutMultiSelection_Click); DeleteMultiSelection.Click += new EventHandler(DeleteMultiSelection_Click); DeselectAll.Click += new EventHandler(DeselectAll_Click);
}//End of try catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw; }//End of catch
} //End of private void AddContextMenuStrip()
/// /// Select all the Controls on the BPMapCanvas /// /// form represents the Active BPMapCanvas public void SelectAll(Form form) { try { //To persist the Save requirement of BPMapCanvas //Because after the following code executed the Save Requirement changes to true //as the selected elements location changes bool IsSaveRequired = false; IsSaveRequired = BPMapCanvasform.IsBPMapCanvasSaveRequired;
//Deselect all the Controls on BPMapCanvas BPMapCanvasform.VortexControl.DeSelectAll(form);
//Remove the multiSection Panel if there exists if (IsMultiSelection == true) { ReleaseMultipleSelection(form);
}//End of if
MultiSelectionPanel = new SelectPanel(); MultiSelectionPanel.Tag = MultiSelectionPanelTag; MultiSelectionPanel.BackColor = MultiSelectBackColor; MultiSelectionPanel.BorderStyle = BorderStyle.FixedSingle; MultiSelectionPanel.Cursor = Cursors.SizeAll; MultiSelectionPanel.AutoSize = true; MultiSelectionPanel.Padding = new Padding(MultiSelectionPadding);
for (int Iteration = 0; Iteration < form.Controls.Count; Iteration++) { Control ControlSelected = form.Controls[Iteration];
//Checking for IBPElements if (ControlSelected is IBPElement) { ((IBPElement)ControlSelected).IsSelected = false; //If the Control is IBPElement then add that control to MultiSelection Elements list MultiSelectedElementsList.Add(ControlSelected);
}//End of if
}//End of for
int SelectionLeft = 0; int SelectionTop = 0;
//To get the left and top position of the MultiSelection panel for (int Iteration = 0; Iteration < MultiSelectedElementsList.Count; Iteration++) { Control ControlSelected = (Control)MultiSelectedElementsList[Iteration];
for (int Iterate = 0; Iterate < MultiSelectedElementsList.Count; Iterate++) { Control ControlOnCanvas = (Control)MultiSelectedElementsList[Iterate]; //If the two control are not the same if (ControlSelected != ControlOnCanvas) { //To get the left postion of the control whose left postion is less than //other controls in the list if (ControlSelected.Left < ControlOnCanvas.Left) { if (SelectionLeft == 0) { SelectionLeft = ControlSelected.Left;
}//End of if else if (SelectionLeft != 0 && SelectionLeft > ControlSelected.Left) { SelectionLeft = ControlSelected.Left;
}//End of else if
}//End of if //to get the top position of the control whose top position is less than //other control on the list if (ControlSelected.Top < ControlOnCanvas.Top) { if (SelectionTop == 0) { SelectionTop = ControlSelected.Top;
}//End of if else if (SelectionTop != 0 && SelectionTop > ControlSelected.Top) { SelectionTop = ControlSelected.Top; }//End of else if
}//End of if
}//End of if
}//End of for
}//End of for
//Assign the Location to MultiSelection panel which are obtained by above code. MultiSelectionPanel.Left = SelectionLeft; MultiSelectionPanel.Top = SelectionTop;
for (int Iteration = 0; Iteration < MultiSelectedElementsList.Count; Iteration++) { Control ControlSelected = (Control)MultiSelectedElementsList[Iteration];
//Make the control invisible to avoid blur. ControlSelected.Visible = false;
//Select the control with White VertexPoints BPMapCanvasform.VortexControl.SelectControl(ControlSelected);
// Need to remove the OriginalEvents of Controls Added to MultiSelection Panel. BPMapCanvasform.RemoveBpMapElementEvents(ControlSelected);
//Add the MultiSelection ContextMenuStrip to InnerControls of MultiSelectionPanel. ControlSelected.ContextMenuStrip = cmnuMultiSelection;
//Assigning new events to the InnerControls of MultiSelection panel AssignEventsToInnerControls(ControlSelected);
//Add controls to the MultiSelection panel MultiSelectionPanel.Controls.Add(ControlSelected);
//Calculations for Locatiuon and size of IneerControls of MultiSelectionPanel ControlSelected.Location = new Point(ControlSelected.Location.X - MultiSelectionPanel.Location.X, ControlSelected.Location.Y - MultiSelectionPanel.Location.Y); ControlSelected.Cursor = Cursors.SizeAll;
//Make the Control Visible to true which ia made false later ControlSelected.Visible = true;
}//End of for
//If there are no controls in MultiSelection then Simply return if (MultiSelectionPanel.Controls.Count == 0) { return;
}//End of if
//set the MultiSelection flag status to true and add the MultiSelection panel to BPMapCanvas IsMultiSelection = true; form.Controls.Add(MultiSelectionPanel); MultiSelectionPanel.SendToBack();
//Set the Selected Control as MultiSelection panel BPMapCanvasform.VortexControl.SelectedControl = MultiSelectionPanel;
//Assign Events to the MultiSelection Panel AssignEventsToMultiSelectionPanel(MultiSelectionPanel);
//Add the ContextMenuStrip to the MultiSelection Panel MultiSelectionPanel.ContextMenuStrip = cmnuMultiSelection;
//with above Operation the Save Requirement of BPMapCanvas Changes //Now assign the previous state which is stored in Another flag before this operation BPMapCanvasform.IsBPMapCanvasSaveRequired = IsSaveRequired;
//Refresh the Element Combobox of Property grid BPMapCanvasform.ObjUIScreen.GetPropertyWindow().RefreshElementCombobox();
//Persist the Start Locations of the MultiSelection //So that it will check wether save is required or not StartLocX = MultiSelectionPanel.Left; StartLocY = MultiSelectionPanel.Top;
//Clear the MultiSelected Elements List MultiSelectedElementsList.Clear();
}//End of try
catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void SelectAll(Form)
/// /// To Copy the MultiSelection to ClipBoard /// public void CopyMultiSelectionPanel() { try { //If the There is no MultiSelection then simply returns. if (MultiSelectionPanel == null) { return; }//End of if
//Copying the MultiSelection Panel to the BPClipBoard. SelectPanel CloneObj = MultiSelectionPanel.clone();
//Release the MultiSelection when Copy Completes //ReleaseMultipleSelection(form); BPMapCanvasform.ObjUIScreen.GetClipBoardToolStrip().SetDataForControl(CloneObj);
}//End of try catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
}//End of public void CopyMultiSelection()
/// /// /// public void CreateMultiSelection() { //Create the MultiSelection if there is more than one control in MultiSelected elements list if (MultiSelectedElementsList.Count > 1) { //Release the MultiSelection before creating another MultiSelection ReleaseMultipleSelection((Form)BPMapCanvasform); //To persist the Save requirement of BPMapCanvas //Because after the following code executed the Save Requirement changes to true //as the selected elements location changes bool IsSaveRequired = false; IsSaveRequired = BPMapCanvasform.IsBPMapCanvasSaveRequired;
//create the MultiSelection Panel MultiSelectionPanel = new SelectPanel(); MultiSelectionPanel.AutoSize = true; MultiSelectionPanel.BackColor = MultiSelectBackColor; MultiSelectionPanel.BorderStyle = BorderStyle.FixedSingle; MultiSelectionPanel.Cursor = Cursors.SizeAll; MultiSelectionPanel.Padding = new Padding(MultiSelectionPadding); //Assign the Tag Value so that it will user later while releasing MultiSelection MultiSelectionPanel.Tag = MultiSelectionPanelTag; MultiSelectionPanel.SendToBack(); //To persist the Left and Top of the Multi Selection Panel int SelectionLeft = 0; int SelectionTop = 0;
//To get the left and top position of the MultiSelection panel for (int Iteration = 0; Iteration < MultiSelectedElementsList.Count; Iteration++) { Control ControlSelected = (Control)MultiSelectedElementsList[Iteration];
for (int Iterate = 0; Iterate < MultiSelectedElementsList.Count; Iterate++) { Control ControlOnCanvas = (Control)MultiSelectedElementsList[Iterate]; //If the Two Controls are not same then if (ControlSelected != ControlOnCanvas) { //To get the Left position of the control whose left postion is //Less than other controls in the List if (ControlSelected.Left <= ControlOnCanvas.Left) { if (SelectionLeft == 0) { SelectionLeft = ControlSelected.Left;
}//End of if else if (SelectionLeft != 0 && SelectionLeft > ControlSelected.Left) { SelectionLeft = ControlSelected.Left;
}//End of else if
}//End of if
//To get the Top Position of the Control whose Top position is //Less than other controls in the List if (ControlSelected.Top <= ControlOnCanvas.Top) { if (SelectionTop == 0) { SelectionTop = ControlSelected.Top;
}//End of if else if (SelectionTop != 0 && SelectionTop > ControlSelected.Top) { SelectionTop = ControlSelected.Top;
}//End of else if
}//End of if
}//End of if
}//End of for
}//End of for
//Assign the Left and Top positions to the MultiSelection Panel which are calculated by using above code MultiSelectionPanel.Left = SelectionLeft; MultiSelectionPanel.Top = SelectionTop;
//Add the Elements which are in Selected Elements Array List to the MultiSelection panel for (int Iteration = 0; Iteration < MultiSelectedElementsList.Count; Iteration++) { Control ControlSelected = (Control)MultiSelectedElementsList[Iteration];
//Set the Selection of each Element in Multi Selection to False ((IBPElement)ControlSelected).IsSelected = false;
//Make the control invisible to avoid blur. ControlSelected.Visible = false;
//Select the control with White VertexPoints BPMapCanvasform.VortexControl.SelectControl(ControlSelected);
// Need to remove the OriginalEvents of Controls Added to MultiSelection Panel. BPMapCanvasform.RemoveBpMapElementEvents(ControlSelected);
//Add the MultiSelection ContextMenuStrip to InnerControls of MultiSelectionPanel. ControlSelected.ContextMenuStrip = cmnuMultiSelection;
//Assigning new events to the InnerControls of MultiSelection panel AssignEventsToInnerControls(ControlSelected);
//Add controls to the MultiSelection panel MultiSelectionPanel.Controls.Add(ControlSelected); //ControlSelected.BringToFront();
//Calculations for Locatiuon and size of IneerControls of MultiSelectionPanel ControlSelected.Location = new Point(ControlSelected.Location.X - MultiSelectionPanel.Location.X, ControlSelected.Location.Y - MultiSelectionPanel.Location.Y); ControlSelected.Cursor = Cursors.SizeAll;
//Make the Control Visible to true which ia made false later ControlSelected.Visible = true;
}//End of for
//Set the Selected Control to MultiSelection Panel BPMapCanvasform.VortexControl.SelectedControl = MultiSelectionPanel; //Assign Events to the MultiSelection Panel AssignEventsToMultiSelectionPanel(MultiSelectionPanel);
//Add the ContextMenuStrip to the MultiSelection Panel MultiSelectionPanel.ContextMenuStrip = cmnuMultiSelection; ((Form)BPMapCanvasform).Controls.Add(MultiSelectionPanel); MultiSelectionPanel.SendToBack();
//set the MultiSelection flag status to true IsMultiSelection = true;
//Refresh the Property Window Element ComboBox to show Nothing BPMapCanvasform.ObjUIScreen.GetPropertyWindow().RefreshElementCombobox();
//Reset the Save Required Flag to Previous value BPMapCanvasform.IsBPMapCanvasSaveRequired = IsSaveRequired;
//Persist the Start Locations of the MultiSelection //So that it will check wether save is required or not StartLocX = MultiSelectionPanel.Left; StartLocY = MultiSelectionPanel.Top;
}//End of if
//If there is less than 2 elements in the List else { //Release the Multi Selection as there is less than 2 elements in the List ReleaseMultipleSelection((Form)BPMapCanvasform); //Select the Control Control SelectedControl = (Control)MultiSelectedElementsList[0]; BPMapCanvasform.VortexControl.SelectControl(SelectedControl); ((IBPElement)SelectedControl).IsSelected = true; //Show the Properties of the Control in the PropertyGrid BPMapCanvasform.ObjUIScreen.GetPropertyWindow().SetSelectedObject(((IBPElement)SelectedControl).GetElementProperties); //UIScreen.BPDPropertiesWindow.SetSelectedObject( BPMapCanvasform.ObjUIScreen.GetPropertyWindow().RefreshElementCombobox(); }//End of else
}//End of public void CreateMultiSelection(ArrayList)
#endregion
} // End of public class MultipleSelectionControl
#endregion
#region InnerTypes
/// /// To Create a Clone Method for MultiSelection Panel /// To copy the MultiSeelction panel to ClipBoard /// public class SelectPanel : Panel { /// /// Creating a Clone of the MultiSelection Panel /// /// public SelectPanel clone() { SelectPanel objMultiSelectionpanel = null; try { objMultiSelectionpanel = new SelectPanel(); objMultiSelectionpanel.Location = this.Location; objMultiSelectionpanel.Tag = this.Tag; objMultiSelectionpanel.Size = this.Size; objMultiSelectionpanel.BackColor = this.BackColor; //objMultiSelectionpanel.BorderStyle = this.BorderStyle; objMultiSelectionpanel.Cursor = this.Cursor; objMultiSelectionpanel.ContextMenu = this.ContextMenu; //(new MultipleSelectionControl()).AssignEventsToMultiSelectionPanel(objMultiSelectionpanel);
//creating a clone of the InnerControls of Multiselection panel and add them to Clone Panel for (int Iteration = 0; Iteration < this.Controls.Count; Iteration++) { if (this.Controls[Iteration] is IBPElement) { //Deselect the Control Before creating Clone (new VortexToControl()).DeSelectControl(this.Controls[Iteration]); IBPElement objIBPElement = (IBPElement)this.Controls[Iteration]; objMultiSelectionpanel.Controls.Add((Control)objIBPElement.Clone()); (new VortexToControl()).SelectControl(this.Controls[Iteration]);
}//End of if
}//End of for
}//End of try catch (BPDBaseException) { throw;
}//End of catch
//As of Now No exception is Anticipated Hence only generic Exception is caught catch (Exception) { throw;
}//End of catch
return objMultiSelectionpanel;
}//End of public SelectPanel clone() }//End of class SelectPanel
#endregion
}
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|