简体   繁体   English

使用Windows表单时,出现{{“参数无效。”}}的异步错误

[英]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. 我有一个简单的Windows窗体,有一个单击按钮,它会加载一个名为高程的列表框,当在属于该高程的ID上单击其中一个高程时,将传递给创建位图并将其返回到原始调用的函数。功能。 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: 您遇到的问题是您正在构建高度和宽度为0的位图:

The following code will also raise the exception: 以下代码也会引发异常:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# Windows Forms 应用程序“参数无效。” - C# Windows Forms App 'Parameter is not valid.' Windows窗体:“ System.ArgumentException:参数无效。”来自系统堆栈 - Windows Forms: “System.ArgumentException: Parameter is not valid.” coming from System stack 使用保存位图时,“参数无效。” - “Parameter is not valid.” when using saving bitmap “参数无效。” - 'Parameter is not valid.' System.ArgumentException:&#39;参数无效。 (showDialog错误) - System.ArgumentException: 'Parameter is not valid.' (showDialog error) &#39;参数无效。&#39; 尝试从数据库 MySql 检索图像时 - 'Parameter is not valid.' when trying to retrive image from database MySql 单击 Pin 时尝试从 API 加载数据 (CustomMap) 错误:指定的转换无效。 - xamarin.forms.maps - Trying to load data from API when Pin is clicked (CustomMap) error: Specified cast is not valid. - xamarin.forms.maps 异步导致参数错误无效 - Async causing error of Parameter is not valid 没有记录时,ExecuteScalar()返回错误“指定的转换无效”。 - ExecuteScalar() return error “Specified cast is not valid.” when there is no record 名单 <image> 异常“参数无效”。 - List<image> exception “Parameter is not valid.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM