Updates to DropDownPanel, Baseline, & Controls

This commit is contained in:
2026-08-05 15:16:53 -04:00
parent 6f0fcdded2
commit 6d7d127b63
14 changed files with 356 additions and 453 deletions
+95 -89
View File
@@ -124,7 +124,7 @@ namespace Volian.Controls.Library
}
public override void SetActive()
{
this.BackColor = MyStepPanel.ActiveColor;
BackColor = MyStepPanel.ActiveColor;
}
public override void SetText()
{
@@ -231,7 +231,7 @@ namespace Volian.Controls.Library
private int _origCfgHt = 0; // keep track if original size was stored in cfg
private int _origCfgWd = 0;
private bool _pastedNew = false; // need this for flagging newly pasted image (may need to clear cfg)
private DisplayTags _displayTags = new DisplayTags();
private readonly DisplayTags _displayTags = new DisplayTags();
#endregion
#region Constructors
@@ -281,8 +281,8 @@ namespace Volian.Controls.Library
MyPictureBox.Width = wd;
MyPictureBox.Height = ht;
MyPictureBox.SizeMode = PictureBoxSizeMode.Zoom;
this.Width = MyPictureBox.Width + ImageMargin;
this.Height = MyPictureBox.Height + 10;
Width = MyPictureBox.Width + ImageMargin;
Height = MyPictureBox.Height + 10;
_newSizeWd = wd / (MyStepPanel.DPI / 72);
_newSizeHt = ht / (MyStepPanel.DPI / 72);
@@ -310,13 +310,10 @@ namespace Volian.Controls.Library
MyPictureBox.Width = wd;
MyPictureBox.Height = ht;
MyPictureBox.SizeMode = PictureBoxSizeMode.Zoom; // as resize matches width/height.
this.Width = MyPictureBox.Width + ImageMargin;
this.Height = MyPictureBox.Height + 10;
if (_displayTags != null)
{
// Set the Height and Width on the step properties page for the new image
_displayTags.SetNewImageHeightAndWidth(ht, wd);
}
Width = MyPictureBox.Width + ImageMargin;
Height = MyPictureBox.Height + 10;
// Set the Height and Width on the step properties page for the new image
_displayTags?.SetNewImageHeightAndWidth(ht, wd);
}
@@ -358,8 +355,8 @@ namespace Volian.Controls.Library
InsType = insType;
FileName = null;
SetupEditItem(itemInfo, myStepPanel, myParentEditItem, myChildRelation, expand, nextEditItem, false);
this.Width = 100 + ImageMargin;
this.Height = 100;
Width = 100 + ImageMargin;
Height = 100;
if (insType == ImageItem.E_ImageSource.File)
{
ImageFileDialog();
@@ -384,21 +381,22 @@ namespace Volian.Controls.Library
}
}
AdjustTableWidthAndLocation();
this.Controls.Add(this._MyPictureBox);
Controls.Add(_MyPictureBox);
AddEventHandlers();
MyStepRTB.RemoveEventHandlers();
MyStepRTB.Visible = false;
}
private void ImageFileDialog()
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
OpenFileDialog openFileDialog1 = new OpenFileDialog
{
InitialDirectory = "c:\\",
Filter = "Image files (*.jpg;*.tif;*.bmp;*.png)|*.jpg;*.tif;*.bmp;*.png|All files (*.*)|*.*",
FilterIndex = 0,
RestoreDirectory = true
};
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "Image files (*.jpg;*.tif;*.bmp;*.png)|*.jpg;*.tif;*.bmp;*.png|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 0;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
@@ -412,13 +410,14 @@ namespace Volian.Controls.Library
_IsDirty = true;
}
}
catch (Exception ex)
{
catch (Exception)
{
FlexibleMessageBox.Show("Could not create image, check file type.", "Error on Image File Selection");
return;
}
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping img for potential future use")]
private static string GetImageFormatExtension(System.Drawing.Image img) => ("jpg"); // seems that this is the only one that works.
#endregion
#region RO_Images
@@ -471,13 +470,11 @@ namespace Volian.Controls.Library
if (val != null && val != "?")
{
string imgname = null;
int W = 0;
int H = 0;
string[] vals = val.Split("\n".ToCharArray());
W = (int)(Int32.Parse(vals[3], System.Globalization.NumberStyles.AllowHexSpecifier) * MyItemInfo.FormatStepData.Font.CharsToTwips);
int lines = Int32.Parse(vals[2], System.Globalization.NumberStyles.AllowHexSpecifier);
H = lines * 12;
try
string[] vals = val.Split("\n".ToCharArray());
int W = (int)(Int32.Parse(vals[3], System.Globalization.NumberStyles.AllowHexSpecifier) * MyItemInfo.FormatStepData.Font.CharsToTwips);
int lines = Int32.Parse(vals[2], System.Globalization.NumberStyles.AllowHexSpecifier);
int H = lines * 12;
try
{
imgname = vals[0];
ROImageInfo roImage = ROImageInfo.GetByROFstID_FileName(rofst.ROFstID, vals[0]);
@@ -492,9 +489,9 @@ namespace Volian.Controls.Library
AddROImageToScreen(W, H, imageText);
}
catch (Exception ex)
{
string msg = string.Format("Could not display image {0}.", imgname);
catch (Exception)
{
string msg = $"Could not display image {imgname}.";
FlexibleMessageBox.Show(msg);
}
}
@@ -511,9 +508,8 @@ namespace Volian.Controls.Library
ProcedureInfo proc = MyItemInfo.MyProcedure;
DocVersionInfo dvi = proc.ActiveParent as DocVersionInfo;
ROFstInfo rofst = dvi.DocVersionAssociations[0].MyROFst;
ROImageInfo roImageInfo = ROImageInfo.GetByROFstID_FileName(rofst.ROFstID, vals[0]);
if (roImageInfo == null) roImageInfo = rofst.GetROImageByFilename(vals[0], MyItemInfo);
if (roImageInfo != null)
ROImageInfo roImageInfo = ROImageInfo.GetByROFstID_FileName(rofst.ROFstID, vals[0]) ?? rofst.GetROImageByFilename(vals[0], MyItemInfo);
if (roImageInfo != null)
{
System.Drawing.Image.GetThumbnailImageAbort myCallback =
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
@@ -526,7 +522,7 @@ namespace Volian.Controls.Library
// if there is config data that saves the resize of the image, use it, otherwise use what was passed in:
StepConfig sc = new StepConfig(MyItemInfo as StepInfo);
SizeF sizef = new Size(1, 1);
if (sc.Step_ImageHeight == null || sc.Step_ImageHeight == 0)
if (sc?.Step_ImageHeight == null || sc.Step_ImageHeight == 0)
{
sizef = new SizeF((img2.Width / img2.HorizontalResolution),
(img2.Height / img2.VerticalResolution));
@@ -555,16 +551,16 @@ namespace Volian.Controls.Library
{
// Always be sure to add the same event handlers to RemoveEventHandlers
MyItemInfo.MyContent.Changed += new VEPROMS.CSLA.Library.ContentInfoEvent(MyContent_Changed);
this.Enter += new System.EventHandler(ImageItem_Enter);
this.MyPictureBox.Enter += new System.EventHandler(ImageItem_Enter);
this.Click += new EventHandler(ImageItem_Click);
this.MyPictureBox.Click += new EventHandler(ImageItem_Click);
this.MyPictureBox.PreviewKeyDown += new PreviewKeyDownEventHandler(ImageItem_PreviewKeyDown); //note that PictureBox does not have cursorkey events
this.MyPictureBox.KeyDown += new KeyEventHandler(ImageItem_KeyDown);
this.MyStepRTB.RoInsert += new StepRTBRoEvent(MyStepRTB_RoInsert);
this.MyStepRTB.DoSaveContents += new StepRTBEvent(MyStepRTB_DoSaveContents); // for storing RO data
this.MyPictureBox.Resize += MyPictureBox_Resize;
this.MyPictureBox.MouseDown += MyPictureBox_MouseDown;
Enter += new System.EventHandler(ImageItem_Enter);
MyPictureBox.Enter += new System.EventHandler(ImageItem_Enter);
Click += new EventHandler(ImageItem_Click);
MyPictureBox.Click += new EventHandler(ImageItem_Click);
MyPictureBox.PreviewKeyDown += new PreviewKeyDownEventHandler(ImageItem_PreviewKeyDown); //note that PictureBox does not have cursorkey events
MyPictureBox.KeyDown += new KeyEventHandler(ImageItem_KeyDown);
MyStepRTB.RoInsert += new StepRTBRoEvent(MyStepRTB_RoInsert);
MyStepRTB.DoSaveContents += new StepRTBEvent(MyStepRTB_DoSaveContents); // for storing RO data
MyPictureBox.Resize += MyPictureBox_Resize;
MyPictureBox.MouseDown += MyPictureBox_MouseDown;
}
void MyPictureBox_MouseDown(object sender, MouseEventArgs e)
@@ -574,10 +570,10 @@ namespace Volian.Controls.Library
void MyPictureBox_Resize(object sender, EventArgs e)
{
if (this.Height != _MyPictureBox.Height + _MyPictureBox.Top + 7) // add in 7 to make it look good // + 10)
if (Height != _MyPictureBox.Height + _MyPictureBox.Top + 7) // add in 7 to make it look good // + 10)
{
LastMethodsPush(string.Format("MyPictureBox_Resize {0}", _MyPictureBox.Height));
this.Height = _MyPictureBox.Height + _MyPictureBox.Top + 7;
Height = _MyPictureBox.Height + _MyPictureBox.Top + 7;
LastMethodsPop();
}
}
@@ -585,16 +581,16 @@ namespace Volian.Controls.Library
{
// Always be sure to add the same event handlers to RemoveEventHandlers
MyItemInfo.MyContent.Changed -= new VEPROMS.CSLA.Library.ContentInfoEvent(MyContent_Changed);
this.Enter -= new System.EventHandler(ImageItem_Enter);
this.MyPictureBox.Enter -= new System.EventHandler(ImageItem_Enter);
this.Click -= new EventHandler(ImageItem_Click);
this.MyPictureBox.Click -= new EventHandler(ImageItem_Click);
this.MyPictureBox.PreviewKeyDown -= new PreviewKeyDownEventHandler(ImageItem_PreviewKeyDown);
this.MyPictureBox.KeyDown -= new KeyEventHandler(ImageItem_KeyDown);
this.MyStepRTB.RoInsert -= new StepRTBRoEvent(MyStepRTB_RoInsert);
this.MyStepRTB.DoSaveContents -= new StepRTBEvent(MyStepRTB_DoSaveContents);
this.MyPictureBox.Resize -= MyPictureBox_Resize;
this.MyPictureBox.MouseDown -= MyPictureBox_MouseDown;
Enter -= new System.EventHandler(ImageItem_Enter);
MyPictureBox.Enter -= new System.EventHandler(ImageItem_Enter);
Click -= new EventHandler(ImageItem_Click);
MyPictureBox.Click -= new EventHandler(ImageItem_Click);
MyPictureBox.PreviewKeyDown -= new PreviewKeyDownEventHandler(ImageItem_PreviewKeyDown);
MyPictureBox.KeyDown -= new KeyEventHandler(ImageItem_KeyDown);
MyStepRTB.RoInsert -= new StepRTBRoEvent(MyStepRTB_RoInsert);
MyStepRTB.DoSaveContents -= new StepRTBEvent(MyStepRTB_DoSaveContents);
MyPictureBox.Resize -= MyPictureBox_Resize;
MyPictureBox.MouseDown -= MyPictureBox_MouseDown;
}
void ImageItem_Click(object sender, EventArgs e)
{
@@ -675,8 +671,8 @@ namespace Volian.Controls.Library
}
void MyStepRTB_RoInsert(object sender, StepRTBRoEventArgs args)
{
int sel = MyStepRTB.SelectionStart + args.ValText.Length;
_IsDirty = true;
_ = MyStepRTB.SelectionStart + args.ValText.Length;
_IsDirty = true;
InsType = E_ImageSource.RoFigure;
MyStepRTB.UpdateStepRtb(args.LinkText, args.ValText);
HandleRoImage();
@@ -725,10 +721,12 @@ namespace Volian.Controls.Library
bool success = MyStepRTB.OrigDisplayText.Save((RichTextBox)MyStepRTB);
if (success && _newSizeHt != 0)
{
StepConfig sc = new StepConfig(MyItemInfo as StepInfo);
sc.Step_ImageWidth = (int)(_newSizeWd / (MyStepPanel.DPI / 72f));
sc.Step_ImageHeight = (int)(_newSizeHt / (MyStepPanel.DPI / 72f));
using (Item item = MyItemInfo.Get())
StepConfig sc = new StepConfig(MyItemInfo as StepInfo)
{
Step_ImageWidth = (int)(_newSizeWd / (MyStepPanel.DPI / 72f)),
Step_ImageHeight = (int)(_newSizeHt / (MyStepPanel.DPI / 72f))
};
using (Item item = MyItemInfo.Get())
{
item.MyContent.Config = sc.ToString();
item.Save();
@@ -761,9 +759,11 @@ namespace Volian.Controls.Library
ImageConfig imgCfg = null;
if (_pastedNew && compressed)
{
imgCfg = new ImageConfig();
imgCfg.Image_DataSize = origLen;
_MyItem.MyContent.MyImage.Config = imgCfg.ToString();
imgCfg = new ImageConfig
{
Image_DataSize = origLen
};
_MyItem.MyContent.MyImage.Config = imgCfg.ToString();
}
else if (_newSizeHt != 0)
{
@@ -800,10 +800,10 @@ namespace Volian.Controls.Library
// this should be saved for every piece of edited data. Note that the set of config
// item Step_MultipleChangeID has the save built in to it.
if (MyItemInfo.ActiveFormat.PlantFormat.FormatData.ProcData.ChangeBarData.ChangeIds
&& !this.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.EditorialChange)
&& !MyStepPanel.MyStepTabPanel.MyDisplayTabControl.EditorialChange)
{
if (sc == null) sc = new StepConfig();
sc.Step_ChangeID = this.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.ChgId;
sc.Step_ChangeID = MyStepPanel.MyStepTabPanel.MyDisplayTabControl.ChgId;
}
// We saved changes. Reset the change bar override.
// IF there is a step config remove the change bar override by setting the CBOverride value to null
@@ -813,8 +813,8 @@ namespace Volian.Controls.Library
sc.Step_CBOverride = null; // clear the change bar override
MyStepRTB.ClearUndo();
}
catch (Exception ex)
{
catch (Exception)
{
FlexibleMessageBox.Show("The image could not be saved.", "Image Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
@@ -825,8 +825,10 @@ namespace Volian.Controls.Library
{
// get filename's extension to map to imageformat:
string ext = fname.Substring(fname.LastIndexOf(".") + 1).ToUpper();
System.Drawing.Imaging.ImageFormat ifmt = System.Drawing.Imaging.ImageFormat.Gif;
switch (ext)
#pragma warning disable IDE0059 // Unnecessary assignment of a value
System.Drawing.Imaging.ImageFormat ifmt = System.Drawing.Imaging.ImageFormat.Gif;
#pragma warning restore IDE0059 // Unnecessary assignment of a value
switch (ext)
{
case ("JPG"):
ifmt = System.Drawing.Imaging.ImageFormat.Jpeg;
@@ -891,12 +893,14 @@ namespace Volian.Controls.Library
}
if (img == null)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "Image files (*.jpg;*.tif;*.bmp;*.png)|*.jpg;*.tif;*.bmp;*.png|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 0;
openFileDialog1.RestoreDirectory = true;
DialogResult dr = openFileDialog1.ShowDialog();
OpenFileDialog openFileDialog1 = new OpenFileDialog
{
InitialDirectory = "c:\\",
Filter = "Image files (*.jpg;*.tif;*.bmp;*.png)|*.jpg;*.tif;*.bmp;*.png|All files (*.*)|*.*",
FilterIndex = 0,
RestoreDirectory = true
};
DialogResult dr = openFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
// check that it is an image
@@ -904,8 +908,8 @@ namespace Volian.Controls.Library
{
img = System.Drawing.Image.FromFile(openFileDialog1.FileName);
}
catch (Exception ex)
{
catch (Exception)
{
img = null;
}
if (img != null) filename = openFileDialog1.FileName;
@@ -939,9 +943,11 @@ namespace Volian.Controls.Library
ImageConfig imgCfg = null;
if (compressed)
{
imgCfg = new ImageConfig();
imgCfg.Image_DataSize = origLen;
_MyItem.MyContent.MyImage.Config = imgCfg.ToString();
imgCfg = new ImageConfig
{
Image_DataSize = origLen
};
_MyItem.MyContent.MyImage.Config = imgCfg.ToString();
}
_MyItem.MyContent.MyImage.Data = imgToByte;
_MyItem.MyContent.MyImage.FileName = filename;
@@ -956,13 +962,13 @@ namespace Volian.Controls.Library
public override void IdentifyMe(bool highlight)
{
if (highlight)
this.BackColor = Color.Gray;
BackColor = Color.Gray;
else
{
if (MyPictureBox.Focused || this.Focused) // If active Set BackColor to the active color
this.BackColor = MyStepPanel.ActiveColor;
if (MyPictureBox.Focused || Focused) // If active Set BackColor to the active color
BackColor = MyStepPanel.ActiveColor;
else // note that the 'inactive' color is actually MyStepPanel.PanelColor
this.BackColor = MyItemInfo.ItemAnnotationCount == 0 ? MyStepPanel.PanelColor : MyStepPanel.AnnotationColor;
BackColor = MyItemInfo.ItemAnnotationCount == 0 ? MyStepPanel.PanelColor : MyStepPanel.AnnotationColor;
}
}
#endregion