void cnvPaint_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetData(typeof(Button)) != null)
            {
                if (((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Name.ToString() == "cnvControls")
                {

                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    Button btn = new Button();
                    btn.Height = 25;
                    btn.Width = 100;
                    btn.Content = "Button";
                    btn.Background = Brushes.Transparent;
                    btn.PreviewMouseDown += new MouseButtonEventHandler(btnDrag_PreviewMouseDown);
                    btn.SetValue(Canvas.LeftProperty, 10.0);
                    btn.SetValue(Canvas.TopProperty, 10.0);

                    ctlPOD objPOD = new ctlPOD();
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 100;
                    
                    objPOD.SetValue(Canvas.LeftProperty, p.X);
                    objPOD.SetValue(Canvas.TopProperty, p.Y);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);

                    objPOD.cnvPOD.Children.Add(btn);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }
                else if ((((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent).GetType() == typeof(ctlPOD))
                {
                    //v
                   // if (currentControl.rect.Visibility == Visibility.Visible)
                    {
                        Point p = e.GetPosition((IInputElement)cnvPaint);
                        ((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X);
                        ((Canvas)((Button)e.Data.GetData(typeof(Button))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y);
                    }
                }
            }

            else if (e.Data.GetData(typeof(Label)) != null)
            {
                if (((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Name.ToString() == "cnvControls")
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    Label lbl = new Label();
                    lbl.Content = "Label";
                    lbl.Background = Brushes.Transparent;
                    lbl.Foreground = Brushes.Black ;
                    lbl.HorizontalContentAlignment = HorizontalAlignment.Center;
                    lbl.Height = 25;
                    lbl.Width = 100;
                    lbl.PreviewMouseDown += new MouseButtonEventHandler(lblDrag_PreviewMouseDown);
                    lbl.SetValue(Canvas.LeftProperty, 10.0);
                    lbl.SetValue(Canvas.TopProperty, 10.0);

                    ctlPOD objPOD = new ctlPOD();
                    objPOD.cnvPOD.Children.Add(lbl);
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 100;
                    objPOD.SetValue(Canvas.LeftProperty, p.X);
                    objPOD.SetValue(Canvas.TopProperty, p.Y);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.KeyDown += new KeyEventHandler(objPOD_KeyDown);
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }

                else if ((((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent).GetType() == typeof(ctlPOD))
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    ((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X);
                    ((Canvas)((Label)e.Data.GetData(typeof(Label))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y);

                }
            }

            else if (e.Data.GetData(typeof(TextBox)) != null)
            {
                if (((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Name.ToString() == "cnvControls")
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    TextBox txt = new TextBox();
                    txt.Cursor = Cursors.Arrow;
                    txt.Background = Brushes.Transparent;
                    txt.Height = 25;
                    txt.Width = 100;
                    txt.Text = "TextBox";
                    txt.MouseDown += new MouseButtonEventHandler(txt_MouseDown);
                    txt.PreviewMouseDown += new MouseButtonEventHandler(txtDrag_PreviewMouseDown);
                    txt.SetValue(Canvas.LeftProperty, 10.0);
                    txt.SetValue(Canvas.TopProperty, 10.0);


                    ctlPOD objPOD = new ctlPOD();
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 100;
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                    objPOD.SetValue(Canvas.LeftProperty, p.X);
                    objPOD.SetValue(Canvas.TopProperty, p.Y);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.cnvPOD.Children.Add(txt);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }
                else if ((((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent).GetType() == typeof(ctlPOD))
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    ((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X);
                    ((Canvas)((TextBox)e.Data.GetData(typeof(TextBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y);
                }
            }

            else if (e.Data.GetData(typeof(TextBlock)) != null)
            {
                if (((Canvas)((TextBlock)e.Data.GetData(typeof(TextBlock))).Parent).Name.ToString() == "cnvControls")
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    TextBlock txb = new TextBlock();

                    txb.Cursor = Cursors.Arrow;
                    txb.Height = 25;
                    txb.Width = 100;
                    txb.Background = Brushes.Transparent;
                    txb.TextWrapping = TextWrapping.Wrap;
                    txb.Text = "TextBlock";
                    txb.PreviewMouseDown += new MouseButtonEventHandler(txbDrag999_PreviewMouseDown);
                    txb.SetValue(Canvas.LeftProperty, 10.0);
                    txb.SetValue(Canvas.TopProperty, 10.0);
                    txb.Foreground = Brushes.Black;

                    ctlPOD objPOD = new ctlPOD();
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 100;
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                    objPOD.SetValue(Canvas.LeftProperty, p.X);
                    objPOD.SetValue(Canvas.TopProperty, p.Y);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.cnvPOD.Children.Add(txb);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }
                else if ((((Canvas)((TextBlock)e.Data.GetData(typeof(TextBlock))).Parent).Parent).GetType() == typeof(ctlPOD))
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    ((Canvas)((TextBlock)e.Data.GetData(typeof(TextBlock))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X);
                    ((Canvas)((TextBlock)e.Data.GetData(typeof(TextBlock))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y);
                }
            }

            else if (e.Data.GetData(typeof(ComboBox)) != null)
            {
                if (((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Name.ToString() == "cnvControls")
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    ComboBox cmb = new ComboBox();
                    cmb.Cursor = Cursors.Arrow;
                    cmb.Height = 25;
                    cmb.Width = 100;
                    cmb.Background = Brushes.Transparent;
                    cmb.Text = "ComboBox";
                    cmb.PreviewMouseDown += new MouseButtonEventHandler(cmb_PreviewMouseDown);
                    cmb.SetValue(Canvas.LeftProperty, 10.0);
                    cmb.SetValue(Canvas.TopProperty, 10.0);

                    ctlPOD objPOD = new ctlPOD();
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 100;
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                    objPOD.SetValue(Canvas.LeftProperty, p.X);
                    objPOD.SetValue(Canvas.TopProperty, p.Y);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.cnvPOD.Children.Add(cmb);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }
                else if ((((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent).GetType() == typeof(ctlPOD))
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    ((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X);
                    ((Canvas)((ComboBox)e.Data.GetData(typeof(ComboBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y);
                }
            }

            else if (e.Data.GetData(typeof(ListBox)) != null)
            {
                if (((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Name.ToString() == "cnvControls")
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    ListBox lst = new ListBox();
                    lst.Cursor = Cursors.Arrow;
                    lst.Height = 25;
                    lst.Width = 100;
                    lst.Background = Brushes.Transparent;
                    lst.PreviewMouseDown += new MouseButtonEventHandler(lst_PreviewMouseDown);
                    lst.SetValue(Canvas.LeftProperty, 10.0);
                    lst.SetValue(Canvas.TopProperty, 10.0);

                    ctlPOD objPOD = new ctlPOD();
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 100;
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                    objPOD.SetValue(Canvas.LeftProperty, p.X);
                    objPOD.SetValue(Canvas.TopProperty, p.Y);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.cnvPOD.Children.Add(lst);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }
                else if ((((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent).GetType() == typeof(ctlPOD))
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    ((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X);
                    ((Canvas)((ListBox)e.Data.GetData(typeof(ListBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y);
                }
            }

            else if (e.Data.GetData(typeof(CheckBox)) != null)
            {
                if (((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Name.ToString() == "cnvControls")
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    CheckBox chk = new CheckBox();
                    chk.Cursor = Cursors.Arrow;
                    chk.Height = 25;
                    chk.Width = 100;
                    chk.Content = "Check Box";
                    chk.Background = Brushes.Transparent;
                    chk.PreviewMouseDown += new MouseButtonEventHandler(chk_PreviewMouseDown);
                    chk.SetValue(Canvas.LeftProperty, 10.0);
                    chk.SetValue(Canvas.TopProperty, 10.0);

                    ctlPOD objPOD = new ctlPOD();
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 100;
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                    objPOD.SetValue(Canvas.LeftProperty, p.X);
                    objPOD.SetValue(Canvas.TopProperty, p.Y);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.cnvPOD.Children.Add(chk);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }
                else if ((((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent).GetType() == typeof(ctlPOD))
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    ((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X);
                    ((Canvas)((CheckBox)e.Data.GetData(typeof(CheckBox))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y);
                }
            }

            else if (e.Data.GetData(typeof(RadioButton)) != null)
            {
                if (((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Name.ToString() == "cnvControls")
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    RadioButton rad = new RadioButton();
                    rad.Cursor = Cursors.Arrow;
                    rad.Height = 25;
                    rad.Width = 100;
                    rad.Content = "Radio Button";
                    rad.Background = Brushes.Transparent;
                    rad.PreviewMouseDown += new MouseButtonEventHandler(rad_PreviewMouseDown);
                    rad.SetValue(Canvas.LeftProperty, 10.0);
                    rad.SetValue(Canvas.TopProperty, 10.0);

                    ctlPOD objPOD = new ctlPOD();
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 100;
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                    objPOD.SetValue(Canvas.LeftProperty, p.X);
                    objPOD.SetValue(Canvas.TopProperty, p.Y);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.cnvPOD.Children.Add(rad);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }
                else if ((((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent).GetType() == typeof(ctlPOD))
                {
                    Point p = e.GetPosition((IInputElement)cnvPaint);
                    ((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent.SetValue(Canvas.LeftProperty, p.X - PrePoint.X);
                    ((Canvas)((RadioButton)e.Data.GetData(typeof(RadioButton))).Parent).Parent.SetValue(Canvas.TopProperty, p.Y - PrePoint.Y);
                }
            }

            newDrag = 1;
            r1.Visibility = Visibility.Collapsed;
            MyPropGrid.ControlToBind = currentControl;
        }
        void FncSetCanvas()
        {
            int flag = 0;
           
            try
            {
                for (int k = 0; k < t1.Length; k++)
                {
                    
                    if (t1[k].Name == "UserControl" + objQueCollection[CurrentQueCount].ID.ToString())
                    {

                        flag = 1;
                        try
                        {
                            UserControl usrCtl = (UserControl)(Activator.CreateInstance(t1[k], null));
                            usrCtl.SetValue(Canvas.LeftProperty, 0.0);
                            MethodInfo mi = t1[k].GetMethod("GetCanvas");//(MemberTypes.Method,BindingFlags.Public
                            Object[] args = new Object[0];
                            Canvas cnvPage = (Canvas)mi.Invoke(usrCtl, args);
                            usrCtl.SetValue(Canvas.TopProperty, 0.0);

                            cnvPaint.Background = cnvPage.Background;


                            int cnt = cnvPage.Children.Count;
                            // need a for loop get all ctls of page
                            for (int i = cnt-1; i >=0; i--)
                            {

                                if (cnvPage.Children[i].GetType() == typeof(Button))
                                {
                                    Button uiCurr = (Button)cnvPage.Children[i];
                                    ctlPOD ctlCurr = new ctlPOD();

                                    ctlCurr.AllowDrop = true;
                                    ctlCurr.Height = (Double)uiCurr.GetValue(HeightProperty);
                                    ctlCurr.Width = (Double)uiCurr.GetValue(WidthProperty);

                                    ctlCurr.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                                    ctlCurr.SetValue(Canvas.LeftProperty, uiCurr.GetValue(Canvas.LeftProperty));
                                    ctlCurr.SetValue(Canvas.TopProperty, uiCurr.GetValue(Canvas.TopProperty));
                                    MyPropGrid.ControlToBind = ctlCurr;

                                    uiCurr.PreviewMouseDown += new MouseButtonEventHandler(btnDrag_PreviewMouseDown);
                                    cnvPage.Children.Remove(uiCurr);
                                    ctlCurr.cnvPOD.Children.Add(uiCurr);

                                    currentControl = ctlCurr;
                                    cnvPaint.Children.Add(ctlCurr);


                                    
                                }

                                else if (cnvPage.Children[i].GetType() == typeof(Label))
                                {
                                    Label uiCurr = (Label)cnvPage.Children[i];
                                    ctlPOD ctlCurr = new ctlPOD();

                                    

                                    ctlCurr.AllowDrop = true;
                                    ctlCurr.Height = (Double)uiCurr.GetValue(HeightProperty);
                                    ctlCurr.Width = (Double)uiCurr.GetValue(WidthProperty);

                                    ctlCurr.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                                    ctlCurr.SetValue(Canvas.LeftProperty, uiCurr.GetValue(Canvas.LeftProperty));
                                    ctlCurr.SetValue(Canvas.TopProperty, uiCurr.GetValue(Canvas.TopProperty));
                                    MyPropGrid.ControlToBind = ctlCurr;

                                    uiCurr.PreviewMouseDown += new MouseButtonEventHandler(lblDrag_PreviewMouseDown);
                                    cnvPage.Children.Remove(uiCurr);
                                    ctlCurr.cnvPOD.Children.Add(uiCurr);
                                    currentControl = ctlCurr;
                                    
                                    cnvPaint.Children.Add(ctlCurr);
                                }

                                else if (cnvPage.Children[i].GetType() == typeof(TextBox))
                                {
                                    TextBox uiCurr = (TextBox)cnvPage.Children[i];
                                    ctlPOD ctlCurr = new ctlPOD();



                                    ctlCurr.AllowDrop = true;
                                    ctlCurr.Height = (Double)uiCurr.GetValue(HeightProperty);
                                    ctlCurr.Width = (Double)uiCurr.GetValue(WidthProperty);

                                    ctlCurr.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                                    ctlCurr.SetValue(Canvas.LeftProperty, uiCurr.GetValue(Canvas.LeftProperty));
                                    ctlCurr.SetValue(Canvas.TopProperty, uiCurr.GetValue(Canvas.TopProperty));
                                    MyPropGrid.ControlToBind = ctlCurr;

                                    uiCurr.PreviewMouseDown += new MouseButtonEventHandler(txtDrag_PreviewMouseDown);
                                    cnvPage.Children.Remove(uiCurr);
                                    ctlCurr.cnvPOD.Children.Add(uiCurr);
                                    currentControl = ctlCurr;

                                    cnvPaint.Children.Add(ctlCurr);
                                }

                                else if (cnvPage.Children[i].GetType() == typeof(TextBlock))
                                {
                                    TextBlock uiCurr = (TextBlock)cnvPage.Children[i];
                                    ctlPOD ctlCurr = new ctlPOD();



                                    ctlCurr.AllowDrop = true;
                                    ctlCurr.Height = (Double)uiCurr.GetValue(HeightProperty);
                                    ctlCurr.Width = (Double)uiCurr.GetValue(WidthProperty);
                                    string str1 = (string)uiCurr.GetValue(ContentProperty);
                                    ctlCurr.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                                    ctlCurr.SetValue(Canvas.LeftProperty, uiCurr.GetValue(Canvas.LeftProperty));
                                    ctlCurr.SetValue(Canvas.TopProperty, uiCurr.GetValue(Canvas.TopProperty));
                                    MyPropGrid.ControlToBind = ctlCurr;
                                  

                                    uiCurr.PreviewMouseDown += new MouseButtonEventHandler(txbDrag999_PreviewMouseDown);//lblDrag_PreviewMouseDown);
                                    cnvPage.Children.Remove(uiCurr);
                                    ctlCurr.cnvPOD.Children.Add(uiCurr);

                                    currentControl = ctlCurr;
                                    cnvPaint.Children.Add(ctlCurr);

                                }
                                else if (cnvPage.Children[i].GetType() == typeof(ComboBox))
                                {
                                    ComboBox uiCurr = (ComboBox)cnvPage.Children[i];
                                    ctlPOD ctlCurr = new ctlPOD();

                                    ctlCurr.AllowDrop = true;
                                    ctlCurr.Height = (Double)uiCurr.GetValue(HeightProperty);
                                    ctlCurr.Width = (Double)uiCurr.GetValue(WidthProperty);
                                    string str1 = (string)uiCurr.GetValue(ContentProperty);
                                    ctlCurr.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                                    ctlCurr.SetValue(Canvas.LeftProperty, uiCurr.GetValue(Canvas.LeftProperty));
                                    ctlCurr.SetValue(Canvas.TopProperty, uiCurr.GetValue(Canvas.TopProperty));
                                    MyPropGrid.ControlToBind = ctlCurr;

                                    uiCurr.PreviewMouseDown += new MouseButtonEventHandler(cmbDrag999_PreviewMouseDown);
                                    cnvPage.Children.Remove(uiCurr);
                                    ctlCurr.cnvPOD.Children.Add(uiCurr);

                                    

                                    currentControl = ctlCurr;

                                    cnvPaint.Children.Add(ctlCurr);
                                }
                                else if (cnvPage.Children[i].GetType() == typeof(ListBox))
                                {
                                    ListBox uiCurr = (ListBox)cnvPage.Children[i];
                                    ctlPOD ctlCurr = new ctlPOD();

                                    ctlCurr.AllowDrop = true;
                                    ctlCurr.Height = (Double)uiCurr.GetValue(HeightProperty);
                                    ctlCurr.Width = (Double)uiCurr.GetValue(WidthProperty);
                                    string str1 = (string)uiCurr.GetValue(ContentProperty);
                                    ctlCurr.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                                    ctlCurr.SetValue(Canvas.LeftProperty, uiCurr.GetValue(Canvas.LeftProperty));
                                    ctlCurr.SetValue(Canvas.TopProperty, uiCurr.GetValue(Canvas.TopProperty));
                                    MyPropGrid.ControlToBind = ctlCurr;

                                    uiCurr.PreviewMouseDown += new MouseButtonEventHandler(lstDrag999_PreviewMouseDown);
                                    cnvPage.Children.Remove(uiCurr);
                                    ctlCurr.cnvPOD.Children.Add(uiCurr);

                                    

                                    currentControl = ctlCurr;
                                    cnvPaint.Children.Add(ctlCurr);
                                }
                                else if (cnvPage.Children[i].GetType() == typeof(RadioButton))
                                {
                                    RadioButton uiCurr = (RadioButton)cnvPage.Children[i];
                                    
                                    ctlPOD ctlCurr = new ctlPOD();

                                    ctlCurr.AllowDrop = true;
                                    ctlCurr.Height = (Double)uiCurr.GetValue(HeightProperty);
                                    ctlCurr.Width = (Double)uiCurr.GetValue(WidthProperty);
                                    string str1 = (string)uiCurr.GetValue(ContentProperty);
                                    ctlCurr.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                                    ctlCurr.SetValue(Canvas.LeftProperty, uiCurr.GetValue(Canvas.LeftProperty));
                                    ctlCurr.SetValue(Canvas.TopProperty, uiCurr.GetValue(Canvas.TopProperty));
                                    MyPropGrid.ControlToBind = ctlCurr;

                                    uiCurr.PreviewMouseDown += new MouseButtonEventHandler(radDrag999_PreviewMouseDown);
                                    cnvPage.Children.Remove(uiCurr);
                                    ctlCurr.cnvPOD.Children.Add(uiCurr);

                                    
                                    currentControl = ctlCurr;

                                    cnvPaint.Children.Add(ctlCurr);
                                }

                                else if (cnvPage.Children[i].GetType() == typeof(CheckBox))
                                {
                                    CheckBox uiCurr = (CheckBox)cnvPage.Children[i];
                                    ctlPOD ctlCurr = new ctlPOD();

                                    ctlCurr.AllowDrop = true;
                                    ctlCurr.Height = (Double)uiCurr.GetValue(HeightProperty);
                                    ctlCurr.Width = (Double)uiCurr.GetValue(WidthProperty);
                                    string str1 = (string)uiCurr.GetValue(ContentProperty);
                                    ctlCurr.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                                    ctlCurr.SetValue(Canvas.LeftProperty, uiCurr.GetValue(Canvas.LeftProperty));
                                    ctlCurr.SetValue(Canvas.TopProperty, uiCurr.GetValue(Canvas.TopProperty));
                                    MyPropGrid.ControlToBind = ctlCurr;
                                    uiCurr.PreviewMouseDown += new MouseButtonEventHandler(chkDrag999_PreviewMouseDown);

                                    cnvPage.Children.Remove(uiCurr);
                                    ctlCurr.cnvPOD.Children.Add(uiCurr);

                                    

                                    currentControl = ctlCurr;
                                    cnvPaint.Children.Add(ctlCurr);
                                }

                            }
                        }
                        catch (Exception exp)
                        {
                            VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "FncsetCanvas", "ctlScriptdesigner.xaml.cs");
                        }
                    }

                }
            }
            catch(Exception er)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(er, "FncSetCanvas", "ctlScriptdesigner.xaml.cs");
            }
           
            //int cntCount = 0;
            if (flag == 0)
            {
                //for (int k = 0; k < t1.Length; k++)
                //{
                //    if (t1[k].Name.Contains("UserControl"))
                //    {
                //        cntCount++;
                //    }
                //}
                //if (cntCount <= objQueCollection.Count)
                FncSetInnerCanvas();
                //int flag2=0;
                //for (int m = 0; m < objQueCollection.Count; m++)
                //{
                //    for (int k = 0; k < t1.Length; k++)
                //    {
                //        if ("UserControl" + objQueCollection[m].ID.ToString() == t1[k].Name )
                //        {
                //            break;
                //        }
                //        else
                //        {
                //            flag2 = 1;
                //        }
                //    }
                //}

            }
            else
            {
                //do nothing
            }

        }
        void FncSetInnerCanvas()
        {
            //cnvPaint.Height = 280;
            //cnvPaint.Width = 700;

            TextBlock lblHeader = new TextBlock();
            lblHeader.Background = Brushes.Transparent;
            lblHeader.TextWrapping = TextWrapping.Wrap;
            lblHeader.Text = objQueCollection[CurrentQueCount].QuestionName;
            lblHeader.PreviewMouseDown += new MouseButtonEventHandler(txbDrag999_PreviewMouseDown);
            lblHeader.FontSize = 19;
            lblHeader.Foreground = Brushes.Black;

            ctlPOD objPOD1 = new ctlPOD();
            objPOD1.AllowDrop = true;
            objPOD1.Height = 45;
            objPOD1.Width = 600;
            objPOD1.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
            objPOD1.SetValue(Canvas.LeftProperty, 25.0);
            objPOD1.SetValue(Canvas.TopProperty, 0.0);
            MyPropGrid.ControlToBind = objPOD1;
            objPOD1.cnvPOD.Children.Add(lblHeader);
            currentControl = objPOD1;
            cnvPaint.Children.Add(objPOD1);

            Label lblQuestion = new Label();
            lblQuestion.Background = Brushes.Transparent;
            lblQuestion.Content = objQueCollection[CurrentQueCount].QuestionText;
            lblQuestion.PreviewMouseDown += new MouseButtonEventHandler(lblDrag_PreviewMouseDown);
            lblQuestion.FontSize = 17;

            lblQuestion.Foreground = Brushes.Black;

            ctlPOD objPOD2 = new ctlPOD();
            objPOD2.AllowDrop = true;
            objPOD2.Height = 45;
            objPOD2.Width = 600;
            objPOD2.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
            objPOD2.SetValue(Canvas.LeftProperty, 0.0);
            objPOD2.SetValue(Canvas.TopProperty, 60.0);
            MyPropGrid.ControlToBind = objPOD2;
            objPOD2.cnvPOD.Children.Add(lblQuestion);
            currentControl = objPOD2;
            cnvPaint.Children.Add(objPOD2);

            ClsOptionCollection objOptCollection = ClsOptionCollection.GetAll(objQueCollection[CurrentQueCount].ID);

            varType = objQueCollection[CurrentQueCount].Category;

            if (varType == "CheckBox")
            {
                for (int i = 0; i < objOptCollection.Count; i++)
                {
                    CheckBox chk = new CheckBox();
                    chk.Background = Brushes.Transparent;
                    chk.Content = objOptCollection[i].Options;
                    chk.Tag = objOptCollection[i].ActionQueueID.ToString() + "," + objOptCollection[i].ID.ToString();
                    chk.PreviewMouseDown += new MouseButtonEventHandler(chkDrag999_PreviewMouseDown);
                    chk.Height = 18;
                    chk.FontSize = 14;
                    varTop = 120 + (30 * i);

                    ctlPOD objPOD = new ctlPOD();
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 600;
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                    objPOD.SetValue(Canvas.LeftProperty, 25.0);
                    objPOD.SetValue(Canvas.TopProperty, varTop);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.cnvPOD.Children.Add(chk);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }
            }
            else if (varType == "RadioButton")
            {
                for (int i = 0; i < objOptCollection.Count; i++)
                {
                    RadioButton chk = new RadioButton();
                    chk.Content = objOptCollection[i].Options;
                    chk.Background = Brushes.Transparent;
                    chk.Tag = objOptCollection[i].ActionQueueID.ToString() + "," + objOptCollection[i].ID.ToString();
                    chk.PreviewMouseDown += new MouseButtonEventHandler(radDrag999_PreviewMouseDown);
                    chk.Height = 18;
                    chk.FontSize = 14;
                    varTop = 120 + (30 * i);

                    ctlPOD objPOD = new ctlPOD();
                    objPOD.AllowDrop = true;
                    objPOD.Height = 25;
                    objPOD.Width = 600;
                    objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                    objPOD.SetValue(Canvas.LeftProperty, 25.0);
                    objPOD.SetValue(Canvas.TopProperty, varTop);
                    MyPropGrid.ControlToBind = objPOD;
                    objPOD.cnvPOD.Children.Add(chk);
                    currentControl = objPOD;
                    cnvPaint.Children.Add(objPOD);
                }
            }
            else if (varType == "ListBox")
            {
                ListBox lst = new ListBox();
                lst.Height = 250;
                lst.Width = 700;
                lst.Tag = "code";
                lst.Background = Brushes.Transparent;
                lst.SetValue(Canvas.LeftProperty, 0.0);
                lst.SetValue(Canvas.TopProperty, 0.0);
                lst.PreviewMouseDown += new MouseButtonEventHandler(lstDrag999_PreviewMouseDown);
                //cnvMain.Children.Add(lst);

                for (int i = 0; i < objOptCollection.Count; i++)
                {
                    ListBoxItem lbi = new ListBoxItem();
                    //lbi.IsEnabled = false;
                    lbi.Content = objOptCollection[i].Options;
                    lbi.Tag = objOptCollection[i].ActionQueueID.ToString() + "," + objOptCollection[i].ID.ToString();
                    lst.Items.Add(lbi);
                }

                ctlPOD objPOD = new ctlPOD();
                objPOD.AllowDrop = true;
                objPOD.Height = 250;
                objPOD.Width = 600;
                objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                objPOD.SetValue(Canvas.LeftProperty, 25.0);
                objPOD.SetValue(Canvas.TopProperty, 120.0);
                MyPropGrid.ControlToBind = objPOD;
                objPOD.cnvPOD.Children.Add(lst);
                currentControl = objPOD;
                cnvPaint.Children.Add(objPOD);
            }
            else if (varType == "ComboBox")
            {
                ComboBox cmb = new ComboBox();
                cmb.Height = 25;
                cmb.Width = 700;
                cmb.Tag = "code";
                cmb.Background = Brushes.Transparent;
                cmb.PreviewMouseDown += new MouseButtonEventHandler(cmbDrag999_PreviewMouseDown);
                //lst.PreviewMouseDown += new MouseButtonEventHandler(lstDrag999_PreviewMouseDown);
                //cnvMain.Children.Add(lst);

                for (int i = 0; i < objOptCollection.Count; i++)
                {
                    ComboBoxItem cbi = new ComboBoxItem();
                    //cbi.IsEnabled = false;
                    cbi.Content = objOptCollection[i].Options;
                    cbi.Tag = objOptCollection[i].ActionQueueID.ToString() + "," + objOptCollection[i].ID.ToString();
                    cmb.Items.Add(cbi);
                }

                ctlPOD objPOD = new ctlPOD();
                objPOD.AllowDrop = true;
                objPOD.Height = 25;
                objPOD.Width = 600;
                objPOD.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
                objPOD.SetValue(Canvas.LeftProperty, 25.0);
                objPOD.SetValue(Canvas.TopProperty, 120.0);
                MyPropGrid.ControlToBind = objPOD;
                objPOD.cnvPOD.Children.Add(cmb);
                currentControl = objPOD;
                cnvPaint.Children.Add(objPOD);
            }

            Button btnNext = new Button();
            btnNext.Content = "Next >> ";
            btnNext.Background = Brushes.Transparent;
            // To Identify That is has some coding and it's Next Button //
            btnNext.Tag = varType.ToString().ToLower();
            btnNext.PreviewMouseDown += new MouseButtonEventHandler(btnDrag_PreviewMouseDown);
            btnNext.FontSize = 16;

            ctlPOD objPOD3 = new ctlPOD();
            objPOD3.AllowDrop = true;
            objPOD3.Height = 35;
            objPOD3.Width = 100;
            objPOD3.PreviewMouseDown += new MouseButtonEventHandler(objPOD_PreviewMouseDown);
            objPOD3.SetValue(Canvas.LeftProperty, 25.0);

            if (objOptCollection.Count == 0 ||varType.ToLower()=="none")
            {
                objPOD3.SetValue(Canvas.TopProperty, 200.0);
            }

            if (varType.ToLower() != "listbox" && varType.ToLower() != "combobox")
            {
                objPOD3.SetValue(Canvas.TopProperty, varTop + 35.0);
            }
            else if (varType.ToLower() == "listbox")
            {
                objPOD3.SetValue(Canvas.TopProperty, 400.0);
            }
            else if (varType.ToLower() == "combobox")
            {
                objPOD3.SetValue(Canvas.TopProperty, 200.0);
            }

            MyPropGrid.ControlToBind = objPOD3;
            objPOD3.cnvPOD.Children.Add(btnNext);
            currentControl = objPOD3;
            cnvPaint.Children.Add(objPOD3);
            varTop = 0;
        }
 void objPOD_PreviewMouseDown(object sender, MouseButtonEventArgs e)
 {
     try
     {
         currentControl = ((ctlPOD)sender);
         currentControl.IsRectvisible = true;
         ((ctlPOD)sender).IsRectvisible = true;
     }
     catch (Exception exp)
     {
         VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "objPOD_PreviewMouseDown", "ctlScriptDesigner.xaml.cs");
     }
 }