StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
sunnyabcd  
#1 Posted : Thursday, May 14, 2020 8:54:55 PM(UTC)
sunnyabcd

Rank: Member

Reputation:

Groups: Approved
Joined: 4/9/2020(UTC)
Posts: 19

Thanks: 7 times
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 7:47:20 AM(UTC)  | Reason: Set post status and description

Yuichi  
#2 Posted : Wednesday, May 20, 2020 3:33:40 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 47
Poland

Thanks: 17 times
Was thanked: 14 time(s) in 11 post(s)
Hi
I'm just working on your script, I just need to improve some things and it will be ready.
Yuichi  
#3 Posted : Wednesday, May 20, 2020 6:04:22 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 47
Poland

Thanks: 17 times
Was thanked: 14 time(s) in 11 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
}
thanks 2 users thanked Yuichi for this useful post.
sunnyabcd on 5/20/2020(UTC), Rob on 5/21/2020(UTC)
sunnyabcd  
#4 Posted : Wednesday, May 20, 2020 7:18:31 PM(UTC)
sunnyabcd

Rank: Member

Reputation:

Groups: Approved
Joined: 4/9/2020(UTC)
Posts: 19

Thanks: 7 times
Originally Posted by: Yuichi Go to Quoted Post
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 Wednesday, May 20, 2020 8:56:24 PM(UTC)  | Reason: Not specified

Rob  
#5 Posted : Wednesday, May 20, 2020 9:15:13 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 636
United States

Thanks: 11 times
Was thanked: 143 time(s) in 125 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.
zyxi  
#6 Posted : Thursday, May 21, 2020 10:28:28 AM(UTC)
zyxi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 3/30/2019(UTC)
Posts: 67
China

Thanks: 7 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
Rob  
#7 Posted : Friday, May 22, 2020 9:01:47 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 636
United States

Thanks: 11 times
Was thanked: 143 time(s) in 125 post(s)
Users browsing this topic
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.