locked
Drag drop test does not work after running setup. RRS feed

  • Question

  • Hi All
    I want to load the PictureBox from the table when I release the picture. When I run the test, it works fine. When I drag the picture on the table, it shows the picturebox but it does not work when I setup the PC and install it on the PC.

    Thanks in advance for your help

    I do not know english, I use to google translate, I apologize if there is a translation error. 

     public Form1()
            {
                InitializeComponent();
                //mouseClicked = false; // aktifkare
                label1.Parent = pictureBox1;       
                pictureBox1.AllowDrop = true;
            }
     public void RefreshImageDrag() // çoklu sayfalı resim yükleme
            {
    #region-----vt bağlantı-----
                con.Open();
                SQLiteCommand veri = new SQLiteCommand("delete From resimler", con);
                veri.ExecuteNonQuery();
                con.Close();
                #endregion
    #region-----iki sayfalı resim yükleme-----                
                myImg = Image.FromFile(files[0]);
                intPages = myImg.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);            
                label2.Text = Convert.ToString(intPages);
                label3.Text = Convert.ToString(intCurrPage + 1);
                myImg.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, intCurrPage); 
                myBmp = new Bitmap(myImg);  
                pictureBox1.Image = myBmp;
    #endregion
    }
     private void pictureBox1_DragDrop(object sender, DragEventArgs e)
            {            
                files = (string[])e.Data.GetData(DataFormats.FileDrop); 
                RefreshImageDrag();
            }
    
            private void pictureBox1_DragEnter(object sender, DragEventArgs e)
            {            
                e.Effect = DragDropEffects.Move;           
            }

    • Moved by CoolDadTx Wednesday, October 25, 2017 1:48 PM Winforms related
    Wednesday, October 25, 2017 1:40 PM

Answers

  • Drag and drop isn't going to work properly if you're dragging between processes running as different users. I suspect you're running your app as admin via UAC. That is a different user as far as Windows is concerned. Drag and drop won't work. This is a security feature.

    If a regular user cannot access the DB then this is a no longer a drag and drop issue but a DB permissions issue. You should post a new question related to your DB permissions issue as it is no longer related to DnD. But you're using SQLite and these forums are for MS products only. You will need to post your SQLite question over in their forums.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by ÖmürTokman Friday, October 27, 2017 2:13 PM
    Friday, October 27, 2017 1:59 PM

All replies

  • You need to add some exception handling to your code and look for errors. Without any other information available I'm going to guess that your RefreshImageDrag is crashing. You're connecting to a DB and working with objects without any sort of validation. Most likely this is throwing an exception. The DB could be missing, the array could be empty, etc. Please add some additional error information including what behavior you're seeing, any exception information including full stack trace and any additional information that will help narrow down the issue.

    On the target machine ensure it can connect to the DB in question.


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, October 25, 2017 1:47 PM
  • The image is loaded when the open file dialog la is loaded.
    I can do all the operations.
    But it is happening with drag drop.


    • Edited by ÖmürTokman Wednesday, October 25, 2017 2:14 PM
    Wednesday, October 25, 2017 2:13 PM
  • What is happening? You haven't clarified - nothing, error, etc. Did you confirm that the DB you're trying to connect to is available? Did you add error handling to help detect any errors?

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, October 25, 2017 2:49 PM
  • does not make any mistakes.

    db bağlantısı tamam.

    no image uploaded via database

    uploading the image with the database disabled

           public void RefreshImageDrag() // çoklu sayfalı resim yükleme
            {
                #region-----vt bağlantı-----
                try
                {
                    con.Open();
                    SQLiteCommand veri = new SQLiteCommand("delete From resimler", con);
                    veri.ExecuteNonQuery();
                    con.Close();
                }
                catch { MessageBox.Show("vt bağlantı hatası"); }
                #endregion
                #region-----iki sayfalı resim yükleme----- 
                try
                {
                    myImg = Image.FromFile(files[0]);
                    intPages = myImg.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);
                    label2.Text = Convert.ToString(intPages);
                    label3.Text = Convert.ToString(intCurrPage + 1);
                    myImg.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, intCurrPage);
                    myBmp = new Bitmap(myImg);
                    pictureBox1.Image = myBmp;
                }
                catch { MessageBox.Show("çoklu resim yükleme hatası"); }
    #endregion

     özel void pictureBox1_DragDrop (nesne göndereni, DragEventArgs e) { try {                 files = ( string []) e . Veri . GetData ( DataFormats . FileDrop ); } catch { MessageBox } . Göster ( "dosyalaraine resim yüklenemedi" ); } Dene { RefreshImageDrag (); } catch { MessageBox } . Göster ( "RefreshImageDrag (); çalışmadı" ); } }
           
               

               
               
               
               
                   
               
               
               
           

            özel void pictureBox1_DragEnter ( nesne göndereni , DragEventArgs e ) { try {                 e . Etki = DragDropEffects . Taşı ; } catch { MessageBox } . Göster ( "DragEnter çalışmıyor" ); } }
               
               

               
               
           




    • Edited by ÖmürTokman Wednesday, October 25, 2017 3:35 PM
    Wednesday, October 25, 2017 2:54 PM
  • We're not going to be able to debug this for you since it is your code. If you can, step through the code on a machine that doesn't work. If not possible then add some logging calls inside your Refresh method so you can narrow down where the failure is coming from.

    //Using way to many fields for this code, simplifying it down
    public void RefreshImageDrag ( string filename, int currentPage ) 
    {
       Debug.WriteLine("Deleting from database");
       ClearTable();
           
       Debug.WriteLine("Reading image");  
       var img = pictureBox1.Image = new Bitmap(filename);
    
       Debug.WriteLine("Getting frame count");
       var frameCount = img.GetFrameCount(FrameDimension.Page);
             
       Debug.WriteLine("Updating UI");
       label2.Text = frameCount.ToString();
       label3.Text = (currentPage + 1).ToString();
    
       //This will fail if current page is beyond the available pages...
       Debug.WriteLine("Selecting active frame");
       img.SelectActiveFrame(FrameDimension.Page, currentPage);            
    }
    
    private void ClearTable ()
    {
       //Really shouldn't be reusing a DB connection, get
       //rid of the field and init the connection here
       using (var con = new SQLiteConnection(...))
       {
          con.Open();
    
          var veri = new SQLiteCommand("delete From resimler", con);
          veri.ExecuteNonQuery();
       };
    }
    
    private void pictureBox1_DragDrop(object sender, DragEventArgs e)        
    {       
       try
       {
          //Should validate first that data is available
          if (!e.Data.GetDataPresent(typeof(string))
             return;
                
          var file = e.Data.GetData(typeof(string) as string;
          if (file == null)
             return;
    
          RefreshImageDrag(file, intCurPage);
       } catch (Exception e)
       {
          MessageBox.Show(e);
       };
    }

    Note that you're using a lot of fields for temporary storage which is generally bad. Use local variables instead. Also you shouldn't keep a DB connection as a field, that is just asking for trouble. The above code was not tested so you need to make some adjustments and you'll need to add some using statements for the unresolved references. To see the log messages on a machine without a debugger installed get DebugView from TechNet and run it. You'll have to enable global Win32 logging in the tool to see .NET messages.

    Also, please post all comments and code in English. These forums only support English. If you'd prefer to use your native locale then you'll need to post in the locale-specific MSDN forums.


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, October 25, 2017 5:28 PM
  • I can do all db-related operations when I run as administrator
    but the drag drop does not work.
    When running as a user, drag drop works but the db connection is giving read-only error.


    Friday, October 27, 2017 6:00 AM
  • Drag and drop isn't going to work properly if you're dragging between processes running as different users. I suspect you're running your app as admin via UAC. That is a different user as far as Windows is concerned. Drag and drop won't work. This is a security feature.

    If a regular user cannot access the DB then this is a no longer a drag and drop issue but a DB permissions issue. You should post a new question related to your DB permissions issue as it is no longer related to DnD. But you're using SQLite and these forums are for MS products only. You will need to post your SQLite question over in their forums.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by ÖmürTokman Friday, October 27, 2017 2:13 PM
    Friday, October 27, 2017 1:59 PM
  • Thank you for everything.
    Friday, October 27, 2017 2:14 PM
  • maybe someone who works

    There is no problem installing the setup setup under ApplicationData.
    Currently I am reaching the sqlite db without admin and drag drop is working.

    Monday, October 30, 2017 8:14 AM