首页 \ 问答 \ 在C#中使用Singleton(Using Singleton in C#)

在C#中使用Singleton(Using Singleton in C#)

我正在尝试创建一个在整个应用程序中使用的类的实例。

我有两种形式:form1和form2,我有一个名为Singleton1的类。

我在form1中创建了一个名为obTest的Singleton1实例:

 Singeton1 obTest = Singleton1.Instance;

从这里我需要从form2访问变量“obTest”。 是否有可能做到这一点? 如何在不创建新的Singleton1变量的情况下访问该变量?

提前致谢。


I'm trying to create an instance of a class to be used throughout the application.

I have two forms: form1 and form2 and I have a class called Singleton1.

I created an instance of Singleton1 in form1 called obTest:

 Singeton1 obTest = Singleton1.Instance;

From here I need to access the variable "obTest" from form2. Is it possible to do this? How I can access that variable without creating a new Singleton1 variable?

Thanks in advance.


原文:https://stackoverflow.com/questions/9468709
更新时间:2023-12-11 16:12

最满意答案

我想我找到了答案

通过使heading具有position:absolute; ,我可以强迫它留在item div里面,防止它移动到它下面。 所以我更新的css(带有实际的class名和制作材料)看起来像;

.flight {
    height: 400px;
    position: relative;

}

.flight-img {
    background: red;
    background-size: cover;
    width: 40%;
    height: 400px;
    float: left;
    position: relative;

    /* CSS Animation Effects */
    transition: width 0.5s ease;

}


.flight-heading {
    width: 60%;
    float: left;
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);

    transition: width 0.5s ease;
}

/* Alternate img float ***
/* Probably an easier way but this works for now */
.flight:nth-of-type(4n-1) .flight-img{
float: right;
}
.flight:nth-of-type(4n-3) .flight-img{
    float: left;
}
.flight:nth-of-type(4n-1) .flight-heading{
    left:0;
}
.flight:nth-of-type(4n-3) .flight-heading{
    float: right;
}

/* Adding hover effects for desktop */

.flight:hover .flight-img {
    width: 100%;
}

.flight:hover .flight-heading {
    width: 100%;
    position:absolute;
    top:0;
    left:0;
    transform: translateY(50%);
    background: rgba(0,0,0,0.75);
    color: #fff;

    h2 {
        color: #fff;
    }
}

而我的HTML看起来像:

<div id="flights">
    <div class="flight">
        <div class="flight-img"></div>
        <div class="flight-heading">
            <h2>Shared Flights</h2>
            <p>The shared flight option is available for 1 to 5 people. This is our most economical flight. You will fly with other passengers that are booked that day.</p>
            <button>Book Now</button>
        </div>
    </div>
    <div class="clear"></div>

</div><!-- End Flights -->

JSFiddle来展示。 我知道动画需要工作,但我认为现在将divs放在一个地方很容易。


I think I found the answer:

by making heading have position:absolute;, I can have it forced to stay inside of the item div, keeping it from moving below it. So my updated css (with actual class names and production stuff) looks like;

.flight {
    height: 400px;
    position: relative;

}

.flight-img {
    background: red;
    background-size: cover;
    width: 40%;
    height: 400px;
    float: left;
    position: relative;

    /* CSS Animation Effects */
    transition: width 0.5s ease;

}


.flight-heading {
    width: 60%;
    float: left;
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);

    transition: width 0.5s ease;
}

/* Alternate img float ***
/* Probably an easier way but this works for now */
.flight:nth-of-type(4n-1) .flight-img{
float: right;
}
.flight:nth-of-type(4n-3) .flight-img{
    float: left;
}
.flight:nth-of-type(4n-1) .flight-heading{
    left:0;
}
.flight:nth-of-type(4n-3) .flight-heading{
    float: right;
}

/* Adding hover effects for desktop */

.flight:hover .flight-img {
    width: 100%;
}

.flight:hover .flight-heading {
    width: 100%;
    position:absolute;
    top:0;
    left:0;
    transform: translateY(50%);
    background: rgba(0,0,0,0.75);
    color: #fff;

    h2 {
        color: #fff;
    }
}

while my html looks like:

<div id="flights">
    <div class="flight">
        <div class="flight-img"></div>
        <div class="flight-heading">
            <h2>Shared Flights</h2>
            <p>The shared flight option is available for 1 to 5 people. This is our most economical flight. You will fly with other passengers that are booked that day.</p>
            <button>Book Now</button>
        </div>
    </div>
    <div class="clear"></div>

</div><!-- End Flights -->

with a JSFiddle to show. I know the animation needs work, but I figure making it smooth will be easy now that the divs stay in one place.

相关问答

更多
  • 您需要在父级上使用:hover伪类,然后选择子元素。 .bg-onebyone:hover .stats-icon { opacity: 0.8; } 此外, .bg-onebyone .widget-stats .stats-icon对于您的HTML标记不正确,因为它将.stats-icon定位为.bg-onebyone ,它不存在。 输出: .bg-onebyone { width: 300px; height: 100px; transition: all 0.5s ease; ...
  • div都向上移动,因为它们与父元素的顶部对齐,并且您在一个底部添加了边距,扩展了父元素。 考虑改为: .dock div{ width:64px; height:64px; background:black; float:left; margin-top: 10px; transition: margin-top 0.5s; } .dock div:hover{ margin-top:0px; } ...即删除顶部的边距而不是在底部添加边距。 The divs are all ...
  • 我想我找到了答案 : 通过使heading具有position:absolute; ,我可以强迫它留在item div里面,防止它移动到它下面。 所以我更新的css(带有实际的class名和制作材料)看起来像; .flight { height: 400px; position: relative; } .flight-img { background: red; background-size: cover; width: 40%; height: 40 ...
  • 使用"transition: all 0.35s;" 而不是"transition: transform 0.35s;" 上 a.box-item .text { display: flex; align-items: center; justify-content: center; position: absolute; top: 0; left: 0; right: 0; ...
  • 我会使用类似下面的解决方案: .btn-icon::after{ content: " " attr(title); text-indent: -9999px; letter-spacing: -10px; opacity: 0; transition: letter-spacing 0.3s ease-out, opacity 0.3s ease-out; } .btn-icon:hover::after{ text-indent: 0px; le ...
  • 只需删除你的z-index: -1; 在#east-exit html { width: 100%; height: 100%; position: absolute; overflow: hidden; font-family: 'Roboto', sans-serif; } #east-exit { display: flex; opacity: 1; align-items: stretch; justify-content: space- ...
  • 在#mydiv上添加转换延迟,然后将其覆盖:hover。 #mydiv{ z-index : 100; top : 50%; left : 50%; -webkit-transition:width 1s, height 1s, background-color 1s ,-webkit-transform 1s, margin-left 1s; transition:width 1s, height 1s, background-color 1s, transfor ...
  • 这是向该州过渡的持续时间。 因此,将0添加到悬停意味着它将是0s转换到悬停状态,然后1s转换回非悬停状态。 如果仅在原始非悬停时,则转换适用于两者。 It's the duration of the transition to that state. So adding 0 to hover means it will be a 0s transition to the hover state and then a 1s transition back to non-hover. If it's only ...
  • 您应该将所有CSS(包括转换)设置为选择器的默认状态,然后仅设置opacity:1; 在悬停状态: div.bx-wrapper div.bx-controls-direction::before{ content: "\f053"; font-family: FontAwesome; font-style: normal; font-weight: normal; text-decoration: inherit; color: #000; ...
  • SharedElementExitTransition用于在将共享元素移动到被调用的Activity之前对共享元素执行某些操作。 例如,您可能希望在被调用的Activity接管之前将其抬起并将其移动到屏幕的中心。 重要的是,在调用startActivity之后执行共享元素退出转换。 因此,您必须在此时对共享元素进行更改。 基本上,你这样做: startActivity(intent, activityOptionsBundleWithTransitions); manipulateSharedElement ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)