/// <summary> /// /// </summary> /// <param name="aColumn"></param> /// <param name="aRow"></param> private void CreateStreamDeckKeyControls(int aColumn, int aRow) { // Compute our key index, it matches hardware index and control index in table control collection int keyIndex = aColumn + iTableLayoutPanelStreamDeck.ColumnCount * aRow; // // Create label // StreamDeck.Label label = new StreamDeck.Label(); label.AllowDrop = true; label.BackColor = Color.Transparent; label.Location = new Point(0, 0); label.Margin = new Padding(KKeyPaddingInPixels); label.BackgroundImageLayout = ImageLayout.Stretch; //label.Name = "label1"; label.Size = new Size(Client.KKeyWidthInPixels, Client.KKeyHeightInPixels); //label.TabIndex = panelIndex; //label.TabStop = true; // Hook in event handlers label.DragDrop += new DragEventHandler(KeyDragDrop); label.DragEnter += new DragEventHandler(KeyDragEnter); label.Click += new EventHandler(KeyClick); label.MouseDown += new MouseEventHandler(KeyMouseDown); // Push key model data into label control LoadKeyInLabel(CurrentProfile.Keys[keyIndex], label); // iTableLayoutPanelStreamDeck.Controls.Add(label, iTableLayoutPanelStreamDeck.ColumnCount - aColumn - 1, aRow); }
/// <summary> /// Event triggered when the user drops some stuff over our control. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> async private void KeyDragDrop(object sender, DragEventArgs e) { string filename; bool supported = GetDragPayloadFilename(out filename, e); if (supported) { // Load our bitmap asynchronously Bitmap bmp = await Task.Run(() => { return(new Bitmap(filename)); }); // Work out drop target key index and make it current StreamDeck.Label ctrl = sender as StreamDeck.Label; // Set target key as current iCurrentKeyIndex = KeyIndexForObject(ctrl); // Update our UI ctrl.BackgroundImage = bmp; // Store the bitmap in our model CurrentKey.Bitmap = bmp; // Upload our key to Stream Deck UploadKey(iCurrentKeyIndex); // Load target key is editor EditCurrentKey(); // Persist our modified model SaveModel(); } else if (e.Data.GetDataPresent(typeof(Key))) { // We are dropping a key on another key // Just swap them then Key source = e.Data.GetData(typeof(Key)) as Key; int sourceIndex = CurrentProfile.Keys.IndexOf(source); int targetIndex = KeyIndexForObject(sender); Key target = CurrentProfile.Keys[targetIndex]; // Swap target and source CurrentProfile.Keys[targetIndex] = source; CurrentProfile.Keys[sourceIndex] = target; iCurrentKeyIndex = targetIndex; SaveModelAndReload(); EditCurrentKey(); } }