Example #1
0
        private IEnumerable <PageLayout> BuildTileUi()
        {
            var textBlockTitle = new TextBlock()
            {
                Color     = Colors.Red.ToBandColor(),
                ElementId = TitleId,
                Rect      = new PageRect(0, 0, 200, 25)
            };
            var barcode = new Barcode(BarcodeType.Code39)
            {
                ElementId = BarcodeId,
                Rect      = new PageRect(0, 0, 250, 40)
            };
            var buttonA = new TextButton
            {
                ElementId = ButtonAId,
                Rect      = new PageRect(0, 0, 100, 45)
            };
            var buttonB = new TextButton
            {
                ElementId = ButtonBId,
                Rect      = new PageRect(0, 0, 100, 45)
            };
            var panelButtons = new ScrollFlowPanel(buttonA, buttonB)
            {
                ElementId   = PanelButtonsId,
                Orientation = FlowPanelOrientation.Horizontal,
                Rect        = new PageRect(0, 0, 250, 250)
            };
            var panelMain = new ScrollFlowPanel(textBlockTitle, barcode, panelButtons)
            {
                Orientation = FlowPanelOrientation.Vertical,
                Rect        = new PageRect(0, 0, 250, 250)
            };

            var bandUi = new List <PageLayout> {
                new PageLayout(panelMain)
            };

            return(bandUi);
        }
        /// <summary>
        ///     Initializes main controls of optimizer.
        /// </summary>
        private void InitializeControls()
        {
            pnlParamsBase    = new Panel();
            pnlParamsBase2   = new Panel();
            pnlCaptions      = new Panel();
            pnlParams        = new Panel();
            pnlCriteriaBase  = new FancyPanel(Language.T("Acceptance Criteria"));
            criteriaPanel    = new ScrollFlowPanel();
            criteriaControls = new CriteriaControls();
            pnlSettings      = new FancyPanel(Language.T("Settings"));
            scrollBar        = new VScrollBar();
            balanceChart     = new SmallBalanceChart();
            progressBar      = new ProgressBar();
            btnOptimize      = new Button();
            btnAccept        = new Button();
            btnCancel        = new Button();

            lblNoParams = new Label();

            fontIndicator = new Font(Font.FontFamily, 11);
            colorText     = LayoutColors.ColorControlText;

            // Panel Parameters Base
            pnlParamsBase.Parent    = this;
            pnlParamsBase.BackColor = LayoutColors.ColorControlBack;
            pnlParamsBase.Paint    += PnlParamsBasePaint;

            // Panel Captions
            pnlCaptions.Parent    = pnlParamsBase;
            pnlCaptions.Dock      = DockStyle.Top;
            pnlCaptions.BackColor = LayoutColors.ColorCaptionBack;
            pnlCaptions.ForeColor = LayoutColors.ColorCaptionText;
            pnlCaptions.Paint    += PnlCaptionsPaint;

            // Panel Parameters Base 2
            pnlParamsBase2.Parent    = pnlParamsBase;
            pnlParamsBase2.BackColor = LayoutColors.ColorControlBack;
            pnlParamsBase2.Resize   += PnlParamsBase2Resize;

            // ScrollBar
            scrollBar.Parent        = pnlParamsBase2;
            scrollBar.Dock          = DockStyle.Right;
            scrollBar.TabStop       = true;
            scrollBar.ValueChanged += ScrollBarValueChanged;
            scrollBar.MouseWheel   += ScrollBarMouseWheel;

            // Panel Parameters
            pnlParams.Parent    = pnlParamsBase2;
            pnlParams.BackColor = LayoutColors.ColorControlBack;

            // Label No Parameters
            lblNoParams.Parent   = pnlParams;
            lblNoParams.Text     = Language.T("There are no parameters suitable for optimization.");
            lblNoParams.AutoSize = true;
            lblNoParams.Visible  = false;

            // Panel Limitations
            pnlCriteriaBase.Parent  = this;
            pnlCriteriaBase.Visible = false;

            // Panel Settings
            pnlSettings.Parent  = this;
            pnlSettings.Visible = false;

            // Small Balance Chart
            balanceChart.Parent    = this;
            balanceChart.BackColor = LayoutColors.ColorControlBack;
            balanceChart.SetChartData();

            // ProgressBar
            progressBar.Parent  = this;
            progressBar.Minimum = 1;
            progressBar.Maximum = 100;
            progressBar.Step    = 1;

            // Button Optimize
            btnOptimize.Parent   = this;
            btnOptimize.Name     = "btnOptimize";
            btnOptimize.Text     = Language.T("Optimize");
            btnOptimize.TabIndex = 0;
            btnOptimize.Click   += BtnOptimizeClick;
            btnOptimize.UseVisualStyleBackColor = true;

            // Button Accept
            btnAccept.Parent                  = this;
            btnAccept.Name                    = "btnAccept";
            btnAccept.Text                    = Language.T("Accept");
            btnAccept.TabIndex                = 1;
            btnAccept.Enabled                 = false;
            btnAccept.DialogResult            = DialogResult.OK;
            btnAccept.UseVisualStyleBackColor = true;

            // Button Cancel
            btnCancel.Parent                  = this;
            btnCancel.Text                    = Language.T("Cancel");
            btnCancel.TabIndex                = 2;
            btnCancel.DialogResult            = DialogResult.Cancel;
            btnCancel.UseVisualStyleBackColor = true;

            // BackGroundWorker
            bgWorker = new BackgroundWorker {
                WorkerReportsProgress = true, WorkerSupportsCancellation = true
            };
            bgWorker.DoWork             += BgWorkerDoWork;
            bgWorker.ProgressChanged    += BgWorkerProgressChanged;
            bgWorker.RunWorkerCompleted += BgWorkerRunWorkerCompleted;
        }
        /// <summary>
        ///     Constructor
        /// </summary>
        public Generator()
        {
            GeneratedDescription = string.Empty;
            strategyBest = Data.Strategy.Clone();
            bestValue = isOOS ? Backtester.Balance(barOOS) : Backtester.NetBalance;
            isGenerating = false;
            isStartegyChanged = false;
            indicatorBlackList = new List<string>();

            colorText = LayoutColors.ColorControlText;

            toolStrip = new ToolStrip();
            strategyField = new StrategyLayout(strategyBest);
            pnlCommon = new FancyPanel(Language.T("Common"));
            pnlCriteriaBase = new FancyPanel(Language.T("Acceptance Criteria"));
            criteriaPanel = new ScrollFlowPanel();
            criteriaControls = new CriteriaControls();
            pnlSettings = new FancyPanel(Language.T("Settings"));
            pnlSorting = new FancyPanel(Language.T("Custom Sorting"));
            pnlTop10 = new FancyPanel(Language.T("Top 10"));
            pnlIndicators = new FancyPanel(Language.T("Indicators"));
            balanceChart = new SmallBalanceChart();
            infpnlAccountStatistics = new InfoPanel();
            progressBar = new ProgressBar();
            lblCalcStrInfo = new Label();
            lblCalcStrNumb = new Label();
            lblBenchmarkInfo = new Label();
            lblBenchmarkNumb = new Label();
            btnAccept = new Button();
            btnGenerate = new Button();
            btnCancel = new Button();
            chbGenerateNewStrategy = new CheckBox();
            chbPreserveSameDirAction = new CheckBox();
            chbPreserveOppDirAction = new CheckBox();
            chbPreservePermSL = new CheckBox();
            chbPreservePermTP = new CheckBox();
            chbPreserveBreakEven = new CheckBox();
            chbInitialOptimization = new CheckBox();
            nudWorkingMinutes = new NumericUpDown();
            chbWorkingMinutes = new CheckBox();

            MaximizeBox = false;
            Icon = Data.Icon;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            BackColor = LayoutColors.ColorFormBack;
            AcceptButton = btnGenerate;
            Text = Language.T("Strategy Generator") + " - " + Data.Symbol + " " + Data.PeriodString + ", " +
                   Data.Bars + " " + Language.T("bars");
            FormClosing += GeneratorFormClosing;

            // Tool Strip
            toolStrip.Parent = this;
            toolStrip.Dock = DockStyle.Top;
            toolStrip.AutoSize = true;

            // Creates a Strategy Layout
            strategyField.Parent = this;
            strategyField.ShowAddSlotButtons = false;
            strategyField.ShowRemoveSlotButtons = false;
            strategyField.ShowPadlockImg = true;
            strategyField.SlotPropertiesTipText = Language.T("Lock or unlock the slot.");
            strategyField.SlotToolTipText = Language.T("Lock, link, or unlock the slot.");

            pnlCommon.Parent = this;
            pnlCriteriaBase.Parent = this;
            pnlSettings.Parent = this;
            pnlSorting.Parent = this;
            pnlTop10.Parent = this;
            pnlIndicators.Parent = this;

            // Small Balance Chart
            balanceChart.Parent = this;
            balanceChart.BackColor = LayoutColors.ColorControlBack;
            balanceChart.Visible = true;
            balanceChart.Cursor = Cursors.Hand;
            balanceChart.IsContextButtonVisible = true;
            balanceChart.PopUpContextMenu.Items.AddRange(GetBalanceChartContextMenuItems());
            balanceChart.Click += AccountOutputClick;
            balanceChart.DoubleClick += AccountOutputClick;
            toolTip.SetToolTip(balanceChart, Language.T("Show account statistics."));
            balanceChart.SetChartData();

            // Info Panel Account Statistics
            infpnlAccountStatistics.Parent = this;
            infpnlAccountStatistics.Visible = false;
            infpnlAccountStatistics.Cursor = Cursors.Hand;
            infpnlAccountStatistics.IsContextButtonVisible = true;
            infpnlAccountStatistics.PopUpContextMenu.Items.AddRange(GetInfoPanelContextMenuItems());
            infpnlAccountStatistics.Click += AccountOutputClick;
            infpnlAccountStatistics.DoubleClick += AccountOutputClick;
            toolTip.SetToolTip(infpnlAccountStatistics, Language.T("Show account chart."));

            // ProgressBar
            progressBar.Parent = this;
            progressBar.Minimum = 1;
            progressBar.Maximum = 100;
            progressBar.Step = 1;

            //Button Generate
            btnGenerate.Parent = this;
            btnGenerate.Name = "Generate";
            btnGenerate.Text = Language.T("Generate");
            btnGenerate.Click += BtnGenerateClick;
            btnGenerate.UseVisualStyleBackColor = true;

            //Button Accept
            btnAccept.Parent = this;
            btnAccept.Name = "Accept";
            btnAccept.Text = Language.T("Accept");
            btnAccept.Enabled = false;
            btnAccept.DialogResult = DialogResult.OK;
            btnAccept.UseVisualStyleBackColor = true;

            //Button Cancel
            btnCancel.Parent = this;
            btnCancel.Text = Language.T("Cancel");
            btnCancel.DialogResult = DialogResult.Cancel;
            btnCancel.UseVisualStyleBackColor = true;

            // BackgroundWorker
            bgWorker = new BackgroundWorker {WorkerReportsProgress = true, WorkerSupportsCancellation = true};
            bgWorker.DoWork += BgWorkerDoWork;
            bgWorker.ProgressChanged += BgWorkerProgressChanged;
            bgWorker.RunWorkerCompleted += BgWorkerRunWorkerCompleted;

            // Apply a Cryptographic Random Seed
            var rng = new RNGCryptoServiceProvider();
            var rndBytes = new byte[4];
            rng.GetBytes(rndBytes);
            int rand = BitConverter.ToInt32(rndBytes, 0);
            random = new Random(rand);

            SetButtonsStrategy();
            SetButtonsGenerator();
            SetPanelCommon();
            SetCriteriaPanel();
            SetPanelSettings();
            SetPanelSorting();
            SetPanelTop10();
            SetPanelIndicators();
            LoadOptions();
            SetCustomSortingUI();
            SetStrategyDescriptionButton();

            chbHideFsb.CheckedChanged += HideFSBClick;

            if (Data.AutostartGenerator)
                BtnGenerateClick(this, new EventArgs());
        }
Example #4
0
        public async Task TestPutTileBand2()
        {
            //Step 1: Connect to Band if need to.
            Message = "Connecting to Band...";
            if (currentBandClient == null)
            {
                //Connect To Band.
                bool isConnected = await InitializeBandConnection();

                //check if connection successful.
                if (isConnected == false)
                {
                    //Something is wrong.
                    Message = "Can't connect to Band. Try Again!";
                    return;
                }
            }

            Message = "Band Connected! Creating Tiles...";

            //Step 2: Create the Tile's Page layout.
            //Would look like this:
            // +--------------------+
            // | Note #1            |       <=== Header Textblock
            // | Angel is the best  |       <=== Wrapperd TextBlock for the Note
            // | girl. Ever <3      |
            // +--------------------+

            //Step 2.1: Create a TextBlock for the Header
            Microsoft.Band.Tiles.Pages.TextBlock myHeaderTextBlock = new TextBlock();

            //Fill The Required Data for the TextBlock (ElementID and Rect):
            //ElementID is the Unique ID of the control (within the layout/page). NOTE: 0 is not a valid ID. Everything has to be positive.
            myHeaderTextBlock.ElementId = 1;

            //Rect: Remember the Rectangle dashed-line in Photoshop when creating a new textbox? That's it. Pretty much the boundary of the control.
            //We will be wrapping this around a ScrollFlowPanel. X,Y of the PageRect will stay 0 (page 39 SDK)

            //Band 1 Workable Width: 245px;
            //Band 2 Workable Width: 258px;
            myHeaderTextBlock.Rect = new Microsoft.Band.Tiles.Pages.PageRect(0, 0, 200, 25);

            //For the Header , let follow the Band Color.? <Does it just stay this way?>
            //myHeaderTextBlock.Color = (await currentBandClient.PersonalizationManager.GetThemeAsync()).Base; <= Not necessarily ? Will be dynamic? Line Blow. Page 40 SDK
            myHeaderTextBlock.ColorSource = ElementColorSource.BandBase;


            //Step 2.2: Create the WrappedTextBlock below for the note.
            Microsoft.Band.Tiles.Pages.WrappedTextBlock myNoteWrappedTextBlock = new WrappedTextBlock();

            //Fill in the required data for the wrapped text block (again, elementID and Rect)
            myNoteWrappedTextBlock.ElementId = 2;
            myNoteWrappedTextBlock.Rect      = new PageRect(0, 0, 250, 100);        //<=== Band 2 Height: 128px ; Band 1 Height: 106px; Wrapped TextBlock should allow displaying a long text with ScrollFlowPanel
            //Actually, the wrapped Textblock seem to not care about the Width?

            //Color should be default of WrappedTextBlock (White)


            //Step 3: Create a Controllers' container. Or the basic layout of the page. Think of it as Grid over the entire window in WPF
            //we use ScrollFlowPanel
            Microsoft.Band.Tiles.Pages.ScrollFlowPanel myPageScrollFlowPanel = new ScrollFlowPanel(myHeaderTextBlock, myNoteWrappedTextBlock);

            //Set the flow of the content to be vertically
            myPageScrollFlowPanel.Orientation = FlowPanelOrientation.Vertical;

            //Set the color of the scroll bar to match the color of the theme that we are using
            myPageScrollFlowPanel.ScrollBarColorSource = ElementColorSource.BandBase;

            //Yet, Rect again. This one should be the entire page.?
            myPageScrollFlowPanel.Rect = new PageRect(0, 0, 250, 128); // Band 2 only


            //Step 4: Create the actual Tile.
            //Step 4.1: Create a Global Unique Identifier for the Tile.
            Guid myGuid = new Guid("D781F673-6D05-4D69-BCFF-EA7E706C3418");

            //Step 4.2 Create the band tile.
            Microsoft.Band.Tiles.BandTile myTile = new BandTile(myGuid);

            //Step 4.3 Setup the properties of the tile. (name, icon, and pageLayout)

            //Name:
            myTile.Name = "My Custom Note Tile";

            //Small and Large Icon.
            //Set the icon following the sample icon that we have from the SDK.
            myTile.TileIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconLarge.png");

            myTile.SmallIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconSmall.png");

            //Create a page layout object from the ScrollFlowPanel that we have.
            Microsoft.Band.Tiles.Pages.PageLayout myPageLayout = new PageLayout(myPageScrollFlowPanel);

            //Add that as the first page (can add up to 8)
            myTile.PageLayouts.Add(myPageLayout);
            myTile.PageLayouts.Add(myPageLayout);

            Message = "Done Creating Tile. Syncing...";

            //Step 5: Sync over to the phone.

            //Step 5.0: Remove old-previous pinned tile.
            //do this to make sure we start fresh everytime.
            await currentBandClient.TileManager.RemoveTileAsync(myTile.TileId);

            //Step 5.1: Sync it over to the phone.
            await currentBandClient.TileManager.AddTileAsync(myTile);


            //Step 6 (EXTRA): We add in a custom data to the page.

            //First one.
            TextBlockData        headerText = new TextBlockData(1, "Note #1");
            WrappedTextBlockData noteText   = new WrappedTextBlockData(2, "Angel is the best girl ever! She is sweet, she is beautiful, she is smart. And after all, she loves me and she is my whole world <3");

            PageData myNotePageData = new PageData(Guid.NewGuid(), 0, headerText, noteText);

            //2nd one
            TextBlockData        headerText2 = new TextBlockData(1, "Note #2");
            WrappedTextBlockData noteText2   = new WrappedTextBlockData(2, "Microsoft Band 2  rocks. This tile was created by Visual Studio 2015, written in C# and Microsoft Band SDK 1.3.20217 on Feb 24th 2016 by Scotty");

            PageData myNotePageData2 = new PageData(Guid.NewGuid(), 1, headerText2, noteText2);

            await currentBandClient.TileManager.SetPagesAsync(myTile.TileId, myNotePageData, myNotePageData2);


            Message = "Done";
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            this.viewModel.StatusMessage = "Running ...";

            try
            {
                // Get the list of Microsoft Bands paired to the phone.
                IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();

                if (pairedBands.Length < 1)
                {
                    this.viewModel.StatusMessage = "This sample app requires a Microsoft Band paired to your device. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.";
                    return;
                }


                // Connect to Microsoft Band.
                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
                {
                    // Create a Tile with a TextButton on it.

                    IEnumerable <BandTile> tileslist = await
                                                       bandClient.TileManager.GetTilesAsync();

                    foreach (var t in tileslist)
                    {
                        if (t.Name == "Fan Control")
                        {
                            a = t.Name;
                        }
                    }

                    if (a != "Fan Control")
                    {
                        Guid myTileId = new Guid("12408A60-13EB-46C2-9D24-F14BF6A033C6");
                        Guid pageId   = Guid.NewGuid();

                        BandTile myTile = new BandTile(myTileId)
                        {
                            Name      = "Fan Control",
                            TileIcon  = await LoadIcon("ms-appx:///Assets/SampleTileIconLarge.png"),
                            SmallIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconSmall.png")
                        };

                        TextButton button = new TextButton()
                        {
                            ElementId = 1, Rect = new PageRect(0, 0, 50, 120)
                        };
                        TextButton button1 = new TextButton()
                        {
                            ElementId = 2, Rect = new PageRect(50, 0, 50, 120)
                        };
                        TextButton button2 = new TextButton()
                        {
                            ElementId = 3, Rect = new PageRect(100, 0, 50, 120)
                        };
                        TextButton button3 = new TextButton()
                        {
                            ElementId = 4, Rect = new PageRect(150, 0, 50, 120)
                        };
                        TextButton button4 = new TextButton()
                        {
                            ElementId = 5, Rect = new PageRect(200, 0, 50, 120)
                        };
                        TextButton button5 = new TextButton()
                        {
                            ElementId = 6, Rect = new PageRect(250, 0, 50, 120)
                        };

                        ScrollFlowPanel panel = new ScrollFlowPanel(button, button1, button2, button3, button4, button5)
                        {
                            Orientation = FlowPanelOrientation.Horizontal,
                            Rect        = new PageRect(0, 0, 320, 120),
                        };
                        myTile.PageLayouts.Add(new PageLayout(panel));


                        //FilledPanel panel1 = new FilledPanel(button1) { Rect = new PageRect(0, 0, 220, 150) };
                        //myTile.PageLayouts.Add(new PageLayout(panel1));

                        // Remove the Tile from the Band, if present. An application won't need to do this everytime it runs.
                        // But in case you modify this sample code and run it again, let's make sure to start fresh.
                        await bandClient.TileManager.RemoveTileAsync(myTileId);

                        // Create the Tile on the Band.
                        await bandClient.TileManager.AddTileAsync(myTile);

                        await bandClient.TileManager.SetPagesAsync(myTileId, new PageData(new Guid("5F5FD06E-BD37-4B71-B36C-3ED9D721F200"), 0, new TextButtonData(1, "1"), new TextButtonData(2, "2"), new TextButtonData(3, "3"), new TextButtonData(4, "4"), new TextButtonData(5, "5"), new TextButtonData(6, "6")));

                        //await bandClient.TileManager.SetPagesAsync(myTileId, new PageData(new Guid("5F5FD06E-BD37-4B71-B36C-3ED9D721F200"), 1, new TextButtonData(2, "Click here2")));

                        // Subscribe to Tile events.
                        int buttonPressedCount = 0;
                    }

                    bandClient.TileManager.TileButtonPressed += TileManager_TileButtonPressed;

                    TaskCompletionSource <bool> closePressed = new TaskCompletionSource <bool>();

                    bandClient.TileManager.TileClosed += (s, args) =>
                    {
                        closePressed.TrySetResult(true);
                    };

                    await bandClient.TileManager.StartReadingsAsync();

                    // Receive events until the Tile is closed.
                    this.viewModel.StatusMessage = "Check the Tile on your Band (it's the last Tile). Waiting for events ...";

                    await closePressed.Task;

                    // Stop listening for Tile events.
                    //  await bandClient.TileManager.StopReadingsAsync();

                    //this.viewModel.StatusMessage = "Done.";
                }
            }
            catch (Exception ex)
            {
                this.viewModel.StatusMessage = ex.ToString();
            }
        }
        /// <summary>
        ///     Initializes main controls of optimizer.
        /// </summary>
        private void InitializeControls()
        {
            pnlParamsBase = new Panel();
            pnlParamsBase2 = new Panel();
            pnlCaptions = new Panel();
            pnlParams = new Panel();
            pnlCriteriaBase = new FancyPanel(Language.T("Acceptance Criteria"));
            criteriaPanel = new ScrollFlowPanel();
            criteriaControls = new CriteriaControls();
            pnlSettings = new FancyPanel(Language.T("Settings"));
            scrollBar = new VScrollBar();
            balanceChart = new SmallBalanceChart();
            progressBar = new ProgressBar();
            btnOptimize = new Button();
            btnAccept = new Button();
            btnCancel = new Button();

            lblNoParams = new Label();

            fontIndicator = new Font(Font.FontFamily, 11);
            colorText = LayoutColors.ColorControlText;

            // Panel Parameters Base
            pnlParamsBase.Parent = this;
            pnlParamsBase.BackColor = LayoutColors.ColorControlBack;
            pnlParamsBase.Paint += PnlParamsBasePaint;

            // Panel Captions
            pnlCaptions.Parent = pnlParamsBase;
            pnlCaptions.Dock = DockStyle.Top;
            pnlCaptions.BackColor = LayoutColors.ColorCaptionBack;
            pnlCaptions.ForeColor = LayoutColors.ColorCaptionText;
            pnlCaptions.Paint += PnlCaptionsPaint;

            // Panel Parameters Base 2
            pnlParamsBase2.Parent = pnlParamsBase;
            pnlParamsBase2.BackColor = LayoutColors.ColorControlBack;
            pnlParamsBase2.Resize += PnlParamsBase2Resize;

            // ScrollBar
            scrollBar.Parent = pnlParamsBase2;
            scrollBar.Dock = DockStyle.Right;
            scrollBar.TabStop = true;
            scrollBar.ValueChanged += ScrollBarValueChanged;
            scrollBar.MouseWheel += ScrollBarMouseWheel;

            // Panel Parameters
            pnlParams.Parent = pnlParamsBase2;
            pnlParams.BackColor = LayoutColors.ColorControlBack;

            // Label No Parameters
            lblNoParams.Parent = pnlParams;
            lblNoParams.Text = Language.T("There are no parameters suitable for optimization.");
            lblNoParams.AutoSize = true;
            lblNoParams.Visible = false;

            // Panel Limitations
            pnlCriteriaBase.Parent = this;
            pnlCriteriaBase.Visible = false;

            // Panel Settings
            pnlSettings.Parent = this;
            pnlSettings.Visible = false;

            // Small Balance Chart
            balanceChart.Parent = this;
            balanceChart.BackColor = LayoutColors.ColorControlBack;
            balanceChart.SetChartData();

            // ProgressBar
            progressBar.Parent = this;
            progressBar.Minimum = 1;
            progressBar.Maximum = 100;
            progressBar.Step = 1;

            // Button Optimize
            btnOptimize.Parent = this;
            btnOptimize.Name = "btnOptimize";
            btnOptimize.Text = Language.T("Optimize");
            btnOptimize.TabIndex = 0;
            btnOptimize.Click += BtnOptimizeClick;
            btnOptimize.UseVisualStyleBackColor = true;

            // Button Accept
            btnAccept.Parent = this;
            btnAccept.Name = "btnAccept";
            btnAccept.Text = Language.T("Accept");
            btnAccept.TabIndex = 1;
            btnAccept.Enabled = false;
            btnAccept.DialogResult = DialogResult.OK;
            btnAccept.UseVisualStyleBackColor = true;

            // Button Cancel
            btnCancel.Parent = this;
            btnCancel.Text = Language.T("Cancel");
            btnCancel.TabIndex = 2;
            btnCancel.DialogResult = DialogResult.Cancel;
            btnCancel.UseVisualStyleBackColor = true;

            // BackGroundWorker
            bgWorker = new BackgroundWorker {WorkerReportsProgress = true, WorkerSupportsCancellation = true};
            bgWorker.DoWork += BgWorkerDoWork;
            bgWorker.ProgressChanged += BgWorkerProgressChanged;
            bgWorker.RunWorkerCompleted += BgWorkerRunWorkerCompleted;
        }
        public DesignedBandTileLayout()
        {
            LoadIconMethod  = LoadIcon;
            AdjustUriMethod = (uri) => uri;

            panel = new ScrollFlowPanel();
            panel.ScrollBarColorSource = ElementColorSource.Custom;
            panel.ScrollBarColor       = new BandColor(255, 255, 255);
            panel.Orientation          = FlowPanelOrientation.Vertical;
            panel.Rect                = new PageRect(-1, 0, 259, 128);
            panel.ElementId           = 1;
            panel.Margins             = new Margins(0, 0, 0, 0);
            panel.HorizontalAlignment = HorizontalAlignment.Left;
            panel.VerticalAlignment   = VerticalAlignment.Top;

            panel2                     = new FlowPanel();
            panel2.Orientation         = FlowPanelOrientation.Vertical;
            panel2.Rect                = new PageRect(0, 0, 78, 128);
            panel2.ElementId           = 2;
            panel2.Margins             = new Margins(0, 0, 0, 0);
            panel2.HorizontalAlignment = HorizontalAlignment.Left;
            panel2.VerticalAlignment   = VerticalAlignment.Top;

            textBlock                     = new TextBlock();
            textBlock.Font                = TextBlockFont.Small;
            textBlock.Baseline            = 0;
            textBlock.BaselineAlignment   = TextBlockBaselineAlignment.Automatic;
            textBlock.AutoWidth           = true;
            textBlock.ColorSource         = ElementColorSource.Custom;
            textBlock.Color               = new BandColor(255, 255, 255);
            textBlock.Rect                = new PageRect(0, 0, 32, 32);
            textBlock.ElementId           = 3;
            textBlock.Margins             = new Margins(0, 0, 0, 0);
            textBlock.HorizontalAlignment = HorizontalAlignment.Left;
            textBlock.VerticalAlignment   = VerticalAlignment.Top;

            panel2.Elements.Add(textBlock);

            textBlock2                     = new TextBlock();
            textBlock2.Font                = TextBlockFont.Small;
            textBlock2.Baseline            = 0;
            textBlock2.BaselineAlignment   = TextBlockBaselineAlignment.Automatic;
            textBlock2.AutoWidth           = true;
            textBlock2.ColorSource         = ElementColorSource.Custom;
            textBlock2.Color               = new BandColor(255, 255, 255);
            textBlock2.Rect                = new PageRect(0, 0, 32, 32);
            textBlock2.ElementId           = 4;
            textBlock2.Margins             = new Margins(0, 0, 0, 0);
            textBlock2.HorizontalAlignment = HorizontalAlignment.Left;
            textBlock2.VerticalAlignment   = VerticalAlignment.Top;

            panel2.Elements.Add(textBlock2);

            textBlock3                     = new TextBlock();
            textBlock3.Font                = TextBlockFont.Small;
            textBlock3.Baseline            = 0;
            textBlock3.BaselineAlignment   = TextBlockBaselineAlignment.Automatic;
            textBlock3.AutoWidth           = true;
            textBlock3.ColorSource         = ElementColorSource.Custom;
            textBlock3.Color               = new BandColor(255, 255, 255);
            textBlock3.Rect                = new PageRect(0, 0, 32, 32);
            textBlock3.ElementId           = 5;
            textBlock3.Margins             = new Margins(0, 0, 0, 0);
            textBlock3.HorizontalAlignment = HorizontalAlignment.Left;
            textBlock3.VerticalAlignment   = VerticalAlignment.Top;

            panel2.Elements.Add(textBlock3);

            textBlock4                     = new TextBlock();
            textBlock4.Font                = TextBlockFont.Small;
            textBlock4.Baseline            = 0;
            textBlock4.BaselineAlignment   = TextBlockBaselineAlignment.Automatic;
            textBlock4.AutoWidth           = true;
            textBlock4.ColorSource         = ElementColorSource.Custom;
            textBlock4.Color               = new BandColor(255, 255, 255);
            textBlock4.Rect                = new PageRect(0, 0, 32, 32);
            textBlock4.ElementId           = 6;
            textBlock4.Margins             = new Margins(0, 0, 0, 0);
            textBlock4.HorizontalAlignment = HorizontalAlignment.Left;
            textBlock4.VerticalAlignment   = VerticalAlignment.Top;

            panel2.Elements.Add(textBlock4);

            panel.Elements.Add(panel2);

            panel3                     = new FlowPanel();
            panel3.Orientation         = FlowPanelOrientation.Vertical;
            panel3.Rect                = new PageRect(0, 0, 47, 128);
            panel3.ElementId           = 7;
            panel3.Margins             = new Margins(86, -128, 0, 0);
            panel3.HorizontalAlignment = HorizontalAlignment.Left;
            panel3.VerticalAlignment   = VerticalAlignment.Top;

            txtCoffee                     = new TextBlock();
            txtCoffee.Font                = TextBlockFont.Small;
            txtCoffee.Baseline            = 0;
            txtCoffee.BaselineAlignment   = TextBlockBaselineAlignment.Automatic;
            txtCoffee.AutoWidth           = true;
            txtCoffee.ColorSource         = ElementColorSource.BandHighlight;
            txtCoffee.Rect                = new PageRect(0, 0, 32, 32);
            txtCoffee.ElementId           = 8;
            txtCoffee.Margins             = new Margins(0, 0, 0, 0);
            txtCoffee.HorizontalAlignment = HorizontalAlignment.Left;
            txtCoffee.VerticalAlignment   = VerticalAlignment.Top;

            panel3.Elements.Add(txtCoffee);

            txtTea                     = new TextBlock();
            txtTea.Font                = TextBlockFont.Small;
            txtTea.Baseline            = 0;
            txtTea.BaselineAlignment   = TextBlockBaselineAlignment.Automatic;
            txtTea.AutoWidth           = true;
            txtTea.ColorSource         = ElementColorSource.BandHighlight;
            txtTea.Rect                = new PageRect(0, 0, 32, 32);
            txtTea.ElementId           = 9;
            txtTea.Margins             = new Margins(0, 0, 0, 0);
            txtTea.HorizontalAlignment = HorizontalAlignment.Left;
            txtTea.VerticalAlignment   = VerticalAlignment.Top;

            panel3.Elements.Add(txtTea);

            txtBeer                     = new TextBlock();
            txtBeer.Font                = TextBlockFont.Small;
            txtBeer.Baseline            = 0;
            txtBeer.BaselineAlignment   = TextBlockBaselineAlignment.Automatic;
            txtBeer.AutoWidth           = true;
            txtBeer.ColorSource         = ElementColorSource.BandHighlight;
            txtBeer.Rect                = new PageRect(0, 0, 32, 32);
            txtBeer.ElementId           = 10;
            txtBeer.Margins             = new Margins(0, 0, 0, 0);
            txtBeer.HorizontalAlignment = HorizontalAlignment.Left;
            txtBeer.VerticalAlignment   = VerticalAlignment.Top;

            panel3.Elements.Add(txtBeer);

            txtWine                     = new TextBlock();
            txtWine.Font                = TextBlockFont.Small;
            txtWine.Baseline            = 0;
            txtWine.BaselineAlignment   = TextBlockBaselineAlignment.Automatic;
            txtWine.AutoWidth           = true;
            txtWine.ColorSource         = ElementColorSource.BandHighlight;
            txtWine.Rect                = new PageRect(0, 0, 32, 32);
            txtWine.ElementId           = 11;
            txtWine.Margins             = new Margins(0, 0, 0, 0);
            txtWine.HorizontalAlignment = HorizontalAlignment.Left;
            txtWine.VerticalAlignment   = VerticalAlignment.Top;

            panel3.Elements.Add(txtWine);

            panel.Elements.Add(panel3);

            panel4                     = new FlowPanel();
            panel4.Orientation         = FlowPanelOrientation.Vertical;
            panel4.Rect                = new PageRect(0, 0, 90, 130);
            panel4.ElementId           = 12;
            panel4.Margins             = new Margins(157, -128, 0, 0);
            panel4.HorizontalAlignment = HorizontalAlignment.Left;
            panel4.VerticalAlignment   = VerticalAlignment.Top;

            btnCoffee = new TextButton();
            btnCoffee.PressedColor        = new BandColor(32, 32, 32);
            btnCoffee.Rect                = new PageRect(0, 0, 90, 32);
            btnCoffee.ElementId           = 13;
            btnCoffee.Margins             = new Margins(0, 0, 0, 0);
            btnCoffee.HorizontalAlignment = HorizontalAlignment.Center;
            btnCoffee.VerticalAlignment   = VerticalAlignment.Top;

            panel4.Elements.Add(btnCoffee);

            btnTea = new TextButton();
            btnTea.PressedColor        = new BandColor(32, 32, 32);
            btnTea.Rect                = new PageRect(0, 0, 90, 32);
            btnTea.ElementId           = 14;
            btnTea.Margins             = new Margins(0, 0, 0, 0);
            btnTea.HorizontalAlignment = HorizontalAlignment.Center;
            btnTea.VerticalAlignment   = VerticalAlignment.Top;

            panel4.Elements.Add(btnTea);

            btnBeer = new TextButton();
            btnBeer.PressedColor        = new BandColor(32, 32, 32);
            btnBeer.Rect                = new PageRect(0, 0, 90, 32);
            btnBeer.ElementId           = 15;
            btnBeer.Margins             = new Margins(0, 0, 0, 0);
            btnBeer.HorizontalAlignment = HorizontalAlignment.Center;
            btnBeer.VerticalAlignment   = VerticalAlignment.Top;

            panel4.Elements.Add(btnBeer);

            btnWine = new TextButton();
            btnWine.PressedColor        = new BandColor(32, 32, 32);
            btnWine.Rect                = new PageRect(0, 0, 90, 32);
            btnWine.ElementId           = 16;
            btnWine.Margins             = new Margins(0, 0, 0, 0);
            btnWine.HorizontalAlignment = HorizontalAlignment.Center;
            btnWine.VerticalAlignment   = VerticalAlignment.Top;

            panel4.Elements.Add(btnWine);

            panel.Elements.Add(panel4);
            pageLayout = new PageLayout(panel);

            PageElementData[] pageElementDataArray = new PageElementData[12];
            pageElementDataArray[0]  = textBlockData;
            pageElementDataArray[1]  = textBlock2Data;
            pageElementDataArray[2]  = textBlock3Data;
            pageElementDataArray[3]  = textBlock4Data;
            pageElementDataArray[4]  = txtCoffeeData;
            pageElementDataArray[5]  = txtTeaData;
            pageElementDataArray[6]  = txtBeerData;
            pageElementDataArray[7]  = txtWineData;
            pageElementDataArray[8]  = btnCoffeeData;
            pageElementDataArray[9]  = btnTeaData;
            pageElementDataArray[10] = btnBeerData;
            pageElementDataArray[11] = btnWineData;

            pageLayoutData = new PageLayoutData(pageElementDataArray);
        }
Example #8
0
        private async void CreateLayout1Button_Click(object sender, EventArgs e)
        {
            // Create a scrollable vertical panel that will hold 2 text messages.
            var panel = new ScrollFlowPanel
            {
                Rect                 = new PageRect(0, 0, 245, 102),
                Orientation          = FlowPanelOrientation.Vertical,
                ScrollBarColorSource = ElementColorSource.BandBase
            };

            // add the text block to contain the first message
            panel.Elements.Add(new WrappedTextBlock
            {
                ElementId = (short)TileMessagesLayoutElementId.Message1,
                Rect      = new PageRect(0, 0, 245, 102),
                // left, top, right, bottom margins
                Margins = new Margins(15, 0, 15, 0),
                Color   = new Microsoft.Band.Portable.BandColor(0xFF, 0xFF, 0xFF),
                Font    = WrappedTextBlockFont.Small
            });

            // add the text block to contain the second message
            panel.Elements.Add(new WrappedTextBlock
            {
                ElementId = (short)TileMessagesLayoutElementId.Message2,
                Rect      = new PageRect(0, 0, 245, 102),
                // left, top, right, bottom margins
                Margins = new Margins(15, 0, 15, 0),
                Color   = new Microsoft.Band.Portable.BandColor(0xFF, 0xFF, 0xFF),
                Font    = WrappedTextBlockFont.Small
            }
                               );

            // create the page layout
            PageLayout layout = new PageLayout(panel);

            try
            {
                // add the layout to the tile
                if (BandHelper.Instance.BandClient == null)
                {
                    await BandHelper.Instance.Connect();
                }

                var tile = await BandHelper.CreateTile("Step5 Tile - Layout 1");

                // get the current set of tiles
                tile.PageLayouts.Add(layout);

                try
                {     // add the tile to the Band
                    if (await BandHelper.Instance.BandClient.TileManager.AddTileAsync(tile))
                    {
                        // tile was successfully added
                        // can proceed to set tile content with SetPagesAsync
                    }
                    else
                    {
                        // tile failed to be added, handle error
                    }
                }
                catch (Exception ex)
                {
                    // handle a Band connection exception
                }

                // specify which layout to use for this page
                var tbd1 = new WrappedTextBlockData
                {
                    ElementId = (Int16)TileMessagesLayoutElementId.Message1,
                    Text      = "This is the text of the first message"
                };

                var tbd2 = new WrappedTextBlockData
                {
                    ElementId = (Int16)TileMessagesLayoutElementId.Message2,
                    Text      = "This is the text of the second message"
                };

                // create a new Guid for the messages page
                var messagesPageGuid = Guid.NewGuid();
                // create the object that contains the page content to be set
                var pageContent = new PageData
                {
                    PageId          = messagesPageGuid,
                    PageLayoutIndex = (int)TileLayoutIndex.MessagesLayout,
                    Data            = { tbd1, tbd2 }
                };

                try
                {     // set the page content on the Band
                    await BandHelper.Instance.BandClient.TileManager
                    .SetTilePageDataAsync(tile.Id, pageContent);
                }
                catch (Exception ex)
                {
                    // handle a Band connection exception
                }
            }
            catch (Exception ex)
            {
                // handle an error adding the layout }
            }
        }