简体   繁体   中英

Async error of {“Parameter is not valid.”} when working with windows forms

I have a simple windows form that has a button to click that loads a listbox of named elevations, when one of the elevations are clicked on the id belonging to that elevation is passed to a function that creates a bitmap and returns it to the original calling function. I keep getting these weird errors.

I keep getting a {"Parameter is not valid."} error.

Any ideas as to whats going on here?

I've also added two screen shots, one of the Window Form and one of the error.

   async void lbElevations_MouseClick(object sender, MouseEventArgs e)
        {
            var bitmapElevation = await ShowElevation();
        }

        async Task<Bitmap> ShowElevation()
        {
            int id = int.Parse(this.lbElevations.SelectedValue.ToString());
            bool isPDF = false;
            Bitmap bitElevation = new Bitmap(0, 0);

            bool Rotate90 = false;
            string action = "getelevation";
            IElevation elev = await ElevationManagerDL.GetElevationAsync(id);


            action = action.ToLower();
            RotateFlipType rotateFlip = Rotate90 ? RotateFlipType.Rotate90FlipNone : RotateFlipType.RotateNoneFlipNone;

            //elevation / shop drawing
            if (action == "getelevation")
            {
                #region Just Elevation
                if (isPDF)
                {
                    using (var pdf = await AlumCloudPlansBL.Manager.GetElevationPDFAsync(elev, true))
                    {
                        //pdf
                    }
                }
                else
                {
                    using (bitElevation = await AlumCloudPlansBL.Manager.GetElevationDrawingAsync(elev, true, rotateFlip, false))
                    {
                        //canvas
                    }
                }
                #endregion
            }

            return bitElevation;
        }

错误

列表框

The problem you are having is that you are constructing a bitmap with 0 height and width:

The following code will also raise the exception:

try
{
    Bitmap b = new Bitmap(0, 0);
}
catch (ArgumentException ex)
{
    MessageBox.Show(ex.ToString());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM