StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
how to allocate a popupmenu to the displayed image?
Rank: Member
Groups: Approved
Joined: 4/10/2020(UTC) Posts: 22
Thanks: 8 times Was thanked: 2 time(s) in 2 post(s)
|
hi,all use the "Snip Screen Area" to make a sanpshot and display as in the examples: Quote: sp.Sleep(100); //Create a new Bitmap in memory var memoryImage = new drawing.System.Drawing.Bitmap(action.Bounds.Width, action.Bounds.Height); //Create a graphics object associated with the bitmap var memoryGraphics = drawing.System.Drawing.Graphics.FromImage(memoryImage); //Copy the screen within the bounding rectangle of the drawn gesture area //I used a square gesture since that seems more intuitive, but it's not neccessary memoryGraphics.CopyFromScreen(action.Bounds.X, action.Bounds.Y, 0, 0, action.Bounds.Size); //Copy the image to the clipboard clip.SetImage(memoryImage); memoryGraphics.Dispose(); memoryImage.Dispose(); pic=sp.DisplayImage(clip.GetImage());
now , i wish when right click on the image, it popup a popupmenu to do sth, how? thanks! Edited by moderator Thursday, May 21, 2020 1:47:20 PM(UTC)
| Reason: Set post status and description
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
Hi I'm just working on your script, I just need to improve some things and it will be ready.
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
Hi I decided that it would be better to write a new window and operate on the image via "forms" libs (pictureBox). I used and modified the "liuxilu#" code (btw good work :)
Scroll up and down - resize Double click - close Left click on picture and drag - move Right click - popup menu
You need to test if it will work correctly for you.Code:sp.Sleep(100);
var memoryImage = new drawing.System.Drawing.Bitmap(action.Bounds.Width, action.Bounds.Height);
var memoryGraphics = drawing.System.Drawing.Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(action.Bounds.X, action.Bounds.Y, 0, 0, action.Bounds.Size);
clip.SetImage(memoryImage);
memoryGraphics.Dispose();
memoryImage.Dispose();
ShowImage(clip.GetImage(), action.Start); // run function (I use "L" gesture so there is "action.Start")
// FUNCTION ////////////////////////////////////////////////////////////////////////////////////////
function ShowImage(img, pt) {
if (img == null) return;
var HD = sp.GetSystemMetricsByIndex(5) + sp.GetSystemMetricsByIndex(32);
HD *= 4; HD += sp.GetSystemMetricsByIndex(4);
var WD = sp.GetSystemMetricsByIndex(6) + sp.GetSystemMetricsByIndex(33);
WD *= 4;
var form = new forms.System.Windows.Forms.Form;
form.StartPosition = forms.System.Windows.Forms.FormStartPosition.Manual;
form.FormBorderStyle = forms.System.Windows.Forms.FormBorderStyle.SizableToolWindow;
form.TopMost = true;
form.ShowInTaskbar = false;
form.Location = pt;
form.Width = img.Width + WD;
form.Height = img.Height + HD;
var pic = new forms.System.Windows.Forms.PictureBox;
pic.SizeMode = forms.System.Windows.Forms.PictureBoxSizeMode.Zoom;
pic.Image = img;
pic.Width = img.Width;
pic.Height = img.Height;
// DOUBLE CLICK / CLOSE
var c_doubleClick = pic.DoubleClick.connect(function (sender, args) {
form.Close();
});
// MANUAL RESIZE
var c_manualResize = form.Resize.connect(function (sender, args) {
pic.Width = form.Width - WD;
pic.Height = form.Height - HD;
});
// MOUSE WHEEL / RESIZE
let n_steps = 100; // adjust this value to your needs !!!
var c_m_wheel = form.MouseWheel.connect(function (sender, e = forms.System.Windows.Forms.MouseEventArgs) {
if (e.Delta > 0 ) { // scoll up
form.Width += n_steps;
form.Height += n_steps;
form.Location = new Point(form.Location.X - Math.round(n_steps/2), form.Location.Y - Math.round(n_steps/2));
form.Update();
} else { // scoll down
if (form.Width > 300 & form.Height > 300) { // protect from 0 value or less
form.Width -= n_steps;
form.Height -= n_steps;
form.Location = new Point(form.Location.X + Math.round(n_steps/2), form.Location.Y + Math.round(n_steps/2));
form.Update();
}
}
});
// LEFT CLICK / DRAG WINDOW
let mouseDown = false;
var c_m_press = pic.MouseDown.connect(function (sender, e = forms.System.Windows.Forms.MouseEventArgs) {
if (e.Button == MouseButtons.Left) {
mouseDown = true;
lastLocation = e.Location;
}
});
var c_m_move = pic.MouseMove.connect(function (sender, e = forms.System.Windows.Forms.MouseEventArgs) {
if (mouseDown) {
form.Location = new Point((form.Location.X - lastLocation.X) + e.X, (form.Location.Y - lastLocation.Y) + e.Y);
form.Update();
}
});
var c_m_relese = pic.MouseUp.connect(function (sender, e = forms.System.Windows.Forms.MouseEventArgs) {
if (e.Button == MouseButtons.Left) {
mouseDown = false;
}
});
// CONTEXTMENU
var contextMenu1 = new forms.System.Windows.Forms.ContextMenu(); // popup menu
var menuItem_1 = contextMenu1.MenuItems.Add("Save File");
var menuItem_2 = contextMenu1.MenuItems.Add("Item 2");
pic.ContextMenu = contextMenu1; // connect to pictureBox
// item 1
var saveFileDialog1 = new forms.System.Windows.Forms.SaveFileDialog(); // initialize "SaveFileDialog"
saveFileDialog1.Filter = "png files (*.png)|*.png|All files (*.*)|*.*" ;
saveFileDialog1.RestoreDirectory = true ;
var c_menuItem_1_clicked = menuItem_1.Click.connect(function (sender, e = forms.System.Windows.Forms.EventArgs) {
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName) { // file are selected or named
pic.Image.Save(saveFileDialog1.FileName, drawing.System.Drawing.Imaging.ImageFormat.Png); // save file
}
});
// item 2
var c_menuItem_2_clicked = menuItem_2.Click.connect(function (sender, e = forms.System.Windows.Forms.EventArgs) {
sp.MessageBox("item 2", "test");
// do something ...
});
form.Controls.Add(pic);
form.ShowDialog();
c_doubleClick.disconnect(); // mouse double click close
c_manualResize.disconnect(); // resize
c_m_wheel.disconnect(); // resize
c_m_press.disconnect(); // mouse left down
c_m_move.disconnect(); // mouse left move
c_m_relese.disconnect(); // mouse left up
c_menuItem_1_clicked.disconnect(); // menu item 1
c_menuItem_2_clicked.disconnect(); // menu item 2
}
|
2 users thanked Yuichi for this useful post.
|
|
|
Rank: Member
Groups: Approved
Joined: 4/10/2020(UTC) Posts: 22
Thanks: 8 times Was thanked: 2 time(s) in 2 post(s)
|
Originally Posted by: Yuichi Hi I decided that it would be better to write a new window and operate on the image via "forms" libs (pictureBox). I used and modified the "liuxilu#" code (btw good work :)
Scroll up and down - resize Double click - close Left click on picture and drag - move Right click - popup menu
You need to test if it will work correctly for you.
thanks, Yuichi, that's waht I want! I have added one word to hide the clos button Quote: form.ControlBox=false;
Edited by user Thursday, May 21, 2020 2:56:24 AM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
Nice work!
I'm really happy to see people helping each other and really getting advanced like this :)
It's why I switched to ClearScript and .NET, so you all could do so much more without needing to have me make updates for very specific requests such as this.
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 3/30/2019(UTC) Posts: 74 Thanks: 8 times Was thanked: 1 time(s) in 1 post(s)
|
Thank you, this script is very good, if you can right-click to save the file directly, in addition to all the borders can be hidden, this script is more perfect
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
|
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
how to allocate a popupmenu to the displayed image?
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close