Code Red > .NET

SetFocus doesn't work!

(1/2) > >>

xys1995:
I have a Windows Form ,and when mouse right clik from a datagridview cell,the program ask user to select an entity in autocad drawing,everything is ok except that the cursor is windows cursor but not  the pickbox。User must click in the drawing and the cusor then changes.
I used the SetFocus Function([DllImport("user32.dll")]) ,but it does not work .Can anybody tells me how to show the pickbox icon automatically?

vs2019+AutoCAD2019



--- Code: ---[DllImport("user32.dll")]
        public static extern System.IntPtr SetFocus(System.IntPtr hwnd);

        private void EntityDataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
                return;

            int rowIdx = e.RowIndex;
            int colIdx = e.ColumnIndex;
            if (rowIdx == -1 || colIdx != 0)
                return;
             
            this.Hide();

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            //SetFocus doesn't work!
            SetFocus(doc.Window.Handle);

            PromptEntityOptions p = new PromptEntityOptions("\nPlease Select\n");
            PromptEntityResult res = ed.GetEntity(p);
            if (res.Status != PromptStatus.OK)
                return;
            ObjectId id = res.ObjectId;

            string layerName = string.Empty;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                DBObject obj = tr.GetObject(id, OpenMode.ForRead);
                if (obj is Entity)
                {
                    Entity ent = obj as Entity;
                    layerName = ent.Layer;
                }
                tr.Commit();
            }

            this.Show();
            MessageBox.Show(layerName);
        }
--- End code ---

It's Alive!:
Hi,

Try this
https://forums.autodesk.com/t5/net/how-to-set-a-focus-to-autocad-main-window-from-my-form-of-c-net/m-p/4680459#M38080

xys1995:
Thank you It's Alive!

I tried the code,and it still can not  work.
I find that if I add a BUTTON control and use Button_Click event,it can work properly.
Besides,I tried DataGridView_CellContentClick and DataGridView_CellClick event, it still can work properly .
And DataGridView_CellMouseClick event can't work! Maybe MouseClick event is special.....

ribarm:
Daniel,
Can I reply from my personal perspective...
It could be perhaps better if you changed your avatar to something more descriptive, or just a little practically more suitfull to alien's eyes... Not sure, but it reminds me on stupid up/down highflyingbirdism... Even flower can have more meaning if you look from it's perspecitve... Someone would say : from certain point of view... Who would that be ???

ronjonp:

--- Quote from: ribarm on June 29, 2022, 07:01:08 AM ---Daniel,
Can I reply from my personal perspective...
It could be perhaps better if you changed your avatar to something more descriptive, or just a little practically more suitfull to alien's eyes... Not sure, but it reminds me on stupid up/down highflyingbirdism... Even flower can have more meaning if you look from it's perspecitve... Someone would say : from certain point of view... Who would that be ???

--- End quote ---
@Ribarm .. are you feeling OK ? That spam yesterday was very odd.  :?

Navigation

[0] Message Index

[#] Next page

Go to full version