Monday, November 5, 2012

Retrieve image, font and color settings from Database in C# windows application


  private void btnpreview_Click(object sender, EventArgs e)
        {
            try
            {
                dt = cs.getTable("select * from [View] where hall='Receiption'", con.con.ConnectionString.ToString());
                if (dt.Rows.Count > 0)
                {
                    Image im = Bitmap.FromFile(dt.Rows[0]["image"].ToString());
                    gbLabels.BackgroundImage = im;

                    TypeConverter converter = TypeDescriptor.GetConverter(typeof(Font));
                    // Saving Font object as a string
                    string fontString = dt.Rows[0]["font"].ToString();
                    string scrollfontString = dt.Rows[0]["scrollfont"].ToString();
                    // Load an instance of Font from a string
                    Font fon = (Font)converter.ConvertFromString(fontString);
                    Font scrollfon = (Font)converter.ConvertFromString(fontString);
                    string color = dt.Rows[0]["color"].ToString();
                    string scrollcolor = dt.Rows[0]["scrollcolor"].ToString();
                    Color col = System.Drawing.ColorTranslator.FromHtml("#" + color);
                    Color scrollcol = System.Drawing.ColorTranslator.FromHtml("#" + scrollcolor);

                    lblEventName.Font = fon;
                    lblEventName.ForeColor = col;
                    lblnotes.Font = fon;
                    lbltime.Font = fon;
                    label2.Font = fon;
                    label1.Font = fon;
                    lblnotes.ForeColor = col;
                    lbltime.ForeColor = col;
                    label2.ForeColor = col;
                    label1.ForeColor = col;
                    dougScrollingTextCtrl1.DougScrollingTextColor1 = scrollcol;
                    dougScrollingTextCtrl1.Font = scrollfon;
                    gbLabels.Visible = true;

                }
            }
            catch (Exception ex)
            {
                Utils.LogHandler.HandleError(ex);
            }
        }

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...